复制代码 代码如下:
-判断某些字段是否为空
–case
select case when ‘字段名’ is null then ‘\n’ else convert(varchar(20),’字段名’) end as ‘newname’
select case when null is null then ‘\n’ else convert(varchar(20),null) end as ‘newname’
–sql server 2005:coalesce
select coalesce(‘字符串类型字段’,’\n’) as ‘newname’
select coalesce(convert(varchar(20),’非字符串类型字段’),’\n’) as ‘newname’
select coalesce(convert(varchar(20),null),’\n’) as ‘newname’
–coalesce,返回其参数中的第一个非空表达式
select coalesce(null,null,1,2,null)union
select coalesce(null,11,12,13,null)union
select coalesce(111,112,113,114,null)