--使用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