读书人

SQL中ISNULL用法示范

发布时间: 2013-11-04 16:56:03 作者: rapoo

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及其示例数据如下图所示。

SQL中ISNULL用法示范

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

SQL中ISNULL用法示范

好了,就到这里了。

读书人网 >SQL Server

热点推荐