SQL中ISNULL用法示例


ISNULLSQL查詢示例SELECT

ISNULL
   使用指定的 替換值替換 NULL。
語法
      :ISNULL ( check_expression , replacement_value )
參數
   check_expression  將被檢查是否為 NULL的表達式。如果不為NULL,這直接返回 該值,也就是 check_expression 這個表達式。如果為空這個直接返回 replacement_value這個表達的內容。。。。check_expression 可以是任何類型的
replacement_value
在 check_expression 為 NULL時將返回的表達式。replacement_value 必須與 check_expresssion 具有相同的類型。
返回類型
       返回與 check_expression 相同的類型。
注釋
如果 check_expression 不為 NULL, 那么返回該表達式的值;否則返回 replacement_value
示例
1 示例數據
表tb_Student及其示例數據如下圖所示。
 
2.查詢要求
   查詢出其中成績(score)小於等於60的學生信息保存至表變量@tempTable中,當學生成績為空時,成績記為0。
1 declare @tempTable table(  
2     stuname nchar(10),  
3     stuage int,   
4      stuscore float);  
5 insert into @tempTable  
6 select name,age,ISNULL(score,0) from tb_Student  
7 where  ISNULL(score,0)<=60  
8 select * from @tempTable  

3 執行結果

 

明白了嗎》》。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM