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

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...