您的位置:首页 > 数据库

设置将查询原结果为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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  null sql server 数据库
相关文章推荐