ISNULL
使用指定的替換值替換 NULL。
語法
:ISNULL ( check_expression , replacement_value )
參數(shù)
check_expression
將被檢查是否為NULL
的表達式。如果不為NULL
,這直接返回 該值,也就是 check_expression
這個表達式。如果為空這個直接返回 replacement_value
這個表達的內(nèi)容。check_expression
可以是任何類型的。
replacement_value
在 check_expression
為 NULL
時將返回的表達式。replacement_value
必須與 check_expresssion
具有相同的類型。
返回類型
返回與 check_expression
相同的類型。
注釋
如果 check_expression
不為 NULL,那么返回該表達式的值;否則返回 replacement_value
。
示例
1 示例數(shù)據(jù)
表tb_Student及其示例數(shù)據(jù)如下圖所示。
2.查詢要求
查詢出其中成績(score)小于等于60的學生信息保存至表變量@tempTable中,當學生成績?yōu)榭諘r,成績記為0。
declare @tempTable table( stuname nchar(10), stuage int, stuscore float); insert into @tempTable select name,age,ISNULL(score,0) from tb_Student where ISNULL(score,0)<=60 select * from @tempTable
3 執(zhí)行結果
推薦教程: 《sql教程》