Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
951 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...