您现在的位置是:网站首页> 编程资料编程资料
sql 实现将空白值替换为其他值_mssql2008_
2023-05-27
422人已围观
简介 sql 实现将空白值替换为其他值_mssql2008_
下图中数据库中查询到的值有空值,包括空白值(“”)和null

如何将上图中的null和空白值替换为其他的值呢??
有人建议使用isnull()函数,但是该函数只能替换null无法替换空白的值。
可以使用下面的sql 语句对null和空白值都替换为其他的值。
select (CASE when (TelPhone IS NULL OR TelPhone='') then '暂无' else TelPhone end) as TelPhone,(CASE when (Name is null or Name='') then '暂无' else Name end) as name,(CASE when (CreateDate IS NULL OR CreateDate='') then '暂无' else CreateDate end) as CreateDate,(CASE when ([Address] IS NULL OR [Address]='') then '暂无' else [Address] end) as [Address] from User_Detail
执行sql语句后效果如下:

上图中我们可以看到所有的null和空白值都替换为了“暂无”。
补充:SQL查询时替换空值
目前我所知道的有三种方法:
1. 使用if语句
select if(age is null,18,age) from student
2. 使用函数:
2.1 isnull
SELECT isnull(age,18) from Student
2.2 coalesce
select coalesce(age,18) from student
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。
您可能感兴趣的文章:
相关内容
- SQL Server 2008 Express 及 Management Studio Express下载安装配置教程_mssql2008_
- Sql Server 2008 精简版(Express)+Management Studio Express第一次安装使用图文教程_mssql2008_
- SQL Server2008 Order by在union子句不可直接使用的原因详解_mssql2008_
- SQLServer搭建网站实例详解_mssql2008_
- SpringMVC统一异常处理三种方法详解_mssql2008_
- SQL Server 2008数据库分布式查询知识_mssql2008_
- sqlserver2008首次登录失败问题及解决方法_mssql2008_
- SQL Server 2008数据库设置定期自动备份的方法_mssql2008_
- SQLServer2008存储过程实现数据插入与更新_mssql2008_
- 解决SQL Server 2008 不能使用 “.” local本地连接数据库问题_mssql2008_
