Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
954 views
in Technique[技术] by (71.8m points)

sql server - IsNull with Equal ¿What does this means?

I have a basic question of SQL

What does the IsNull()=0 means in this code? As far as I know, = assigns a value, but in this case it is used inside a Where statement. Hope somebody can explain it to me :)

    Where       vol.espe_codigo =   matriz.espe_codigo
    And         IsNull(costo_gerencias.plde_codigo,0)   =   0
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

isnull(firstvalue, secondvalue) tests if the value for firstvalue is NULL or not. When the value is not null than this value is returned, but when the value is null than the value of secondvalue is returned.

Examples :

declare @test varchar(100) = 'abc'
declare @test2 varchar(100) = '123'

isnull(@test, @test2) will return 'abc'

second example :

declare @test varchar(100) = null
declare @test2 varchar(100) = '123'

isnull(@test, @test2) will return '123'

third example :

declare @test varchar(100) = ''
declare @test2 varchar(100) = '123'

isnull(@test, @test2) will return ''

I use it most to check on varchar columns, since they may contain an empty string which is not the same as NULL, but in a DataGridView or TextBox you cannot see the difference.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...