设置将查询原结果为NULL的字段值置为0.0(数值型)或‘’(字符型)
2005-03-31 08:52
477 查看
--使用SQL Server自带之范例数据库pubs。其中原price字段类型为Money,notes字段类型为varchar(200)
--通用做法(好处在于不仅可以应用于转零,还可以转为任何想要的值):
select title, 'Price123' =
case
when price is null then 0.0
else price
end, type,
'notes123' =
case
when notes is null then ''
else notes
end
from pubs.dbo.titles
--一般做法(仅限此处转零应用):
select
title,
IsNull(price, 0) as price123,
type,
IsNull(notes, 'unnoted') as notes123
from pubs.dbo.titles
--通用做法(好处在于不仅可以应用于转零,还可以转为任何想要的值):
select title, 'Price123' =
case
when price is null then 0.0
else price
end, type,
'notes123' =
case
when notes is null then ''
else notes
end
from pubs.dbo.titles
--一般做法(仅限此处转零应用):
select
title,
IsNull(price, 0) as price123,
type,
IsNull(notes, 'unnoted') as notes123
from pubs.dbo.titles
相关文章推荐
- MyBatis查询返回Map时设置值为null的字段也在结果集中
- springboot+mybatis MyBatis查询返回Map时设置值为null的字段没有在结果集中
- Spring boot + MyBatis 查询返回Map时设置值为null的字段也在结果集中
- Hive 1.1.0 某些字段的查询结果为NULL
- sql 查询结果为null的设置默认数据
- mybatis 使用oracle char 字段查询返回结果总是null
- 多字段模糊查询,前一个字段无搜索结果返回null时不影响后一个字段模糊查询
- 数据库中某字段中含空值,查询结果报NullpointerException
- SQL 查询的结果某个字段是Null,用默认的值代替
- 解决mybatis使用char类型字段查询oracle数据库时结果返回null问题
- mybatis使用char类型字段查询oracle数据库时结果返回null
- myBatis 常见问题(一)查询结果字段为null
- mybatis 使用oracle char 字段查询返回结果总是null
- 在Mybaties中进行数据查询时,表中字段名和属相名没有对应起来,查询的结果总null,一下是解决方法
- 转自:http://m.blog.csdn.net/article/details?id=6554168 在使用order by语句进行查询结果排序时,不同的数据库对于被排序字段数据行为null的情况
- "Microsoft Office Access 不能在追加查询中追加所有记录。 Microsoft Office Access设置1字段为Null是因为类型转换失败,它未将0记录添加到表是因为键值冲突,没有添加0记录是因为锁定冲突,没有添加0记录是因为
- mybatis查询类型为int的字段,返回null的异常
- Oracle 数据库中关于对表字段约束的操作(设置、删除、查询)
- Spring mvc mybatis 查询结果缺少字段
- oracle查询字段结果字符串拼接