SQL Server 对于NULL字段如何处理

SQL Server 的某些表字段默认是NULL,对于NULL字段如何处理?

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
-判断某些字段是否为空
--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 )

你可能感兴趣的:(数据库)