34,872
社区成员
发帖
与我相关
我的任务
分享
create table tb(col int)
insert into tb values(0)
insert into tb values(0)
insert into tb values(1)
insert into tb values(2)
insert into tb values(3)
insert into tb values(0)
insert into tb values(0)
go
select col , newcol = (case when col = 0 then null else col end ) from tb
drop table tb
/*
col newcol
----------- -----------
0 NULL
0 NULL
1 1
2 2
3 3
0 NULL
0 NULL
(所影响的行数为 7 行)
*/NULLIF
如果两个指定的表达式相等,则返回空值。
语法
NULLIF ( expression , expression )
参数
expression
常量、列名、函数、子查询或算术运算符、按位运算符以及字符串运算符的任意组合。
返回类型
返回类型与第一个 expression 相同。
如果两个表达式不相等,NULLIF 返回第一个 expression 的值。如果相等,NULLIF 返回第一个 expression 类型的空值。
注释
如果两个表达式相等且结果表达式为 NULL,NULLIF 等价于 CASE 的搜索函数。nullif(col,0)