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 执行结果

原文地址:https://www.cnblogs.com/ypyp123/p/13444399.html