mssqlsqlserver将字段null(空值)值替换为指定值的三种⽅法
分享
摘要:
下⽂将分享两种将字段中null值替换为指定值的⽅法分享,如下所⽰:
实验环境:sqlserver 2008 R2
例:
create table test(keyId int identity, info varchar(30))
go
insert into test(info)values('a'),('b'),(null),('d')
go
---⽅法1:使⽤isnull替换
select keyId,isnull(info,'替换null值')  as info from test
go
isnull的用法
---⽅法2:使⽤case when 替换
select keyId,case  when info is null then '替换null值' else info  end as info  from test
---⽅法3:使⽤coalesce替换相应的值
select keyId , coalesce(info,'替换null值') as info from test
go
truncate table test
drop table test

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。