当前位置: 代码迷 >> SQL >> SQL中ISNULL用法示范
  详细解决方案

SQL中ISNULL用法示范

热度:77   发布时间:2016-05-05 11:55:42.0
SQL中ISNULL用法示例

ISNULL

使用指定的替换值替换 NULL

语法
ISNULL ( check_expression , replacement_value )

参数
check_expression

将被检查是否为 NULL的表达式。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

declare @tempTable table(	stuname nchar(10),	stuage int,	               stuscore float);insert into @tempTableselect name,age,ISNULL(score,0) from tb_Studentwhere  ISNULL(score,0)<=60select * from @tempTable

3 执行结果

好了,就到这里了。