sqlserver对字段出现NULL值的处理

编程学习 2021-07-05 13:42www.dzhlxh.cn编程入门
SQL Server 的某些表字段默认是NULL,对于NULL字段如何处理?
代码如下:

-判断某些字段是否为空
--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)

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板