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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…