復制代碼 代碼如下:
-判斷某些字段是否為空
--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)