请问怎么把null转换为0

kvkensin9 2010-09-28 10:08:28
请问怎么把视图的null转换为0?谢谢
...全文
146 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
claro 2010-09-28
  • 打赏
  • 举报
回复
(SQL2005及以上)字段可以是字符型(隐式转换了),比如:
--table a (bz char(1),bh varchar(20))
select * from a

--result:
bz bh
---- --------------------
NULL 085
247
0 122

(3 行受影响)


select ISNULL(bz,0) from a
--result:
----
0

0

(3 行受影响)



更多参考:
http://topic.csdn.net/u/20100828/08/902fd855-af77-46c4-ad07-164fbf094e31.html
dawugui 2010-09-28
  • 打赏
  • 举报
回复
[Quote=引用楼主 kvkensin9 的回复:]
请问怎么把视图的null转换为0?谢谢
[/Quote]
isnull(col,0)
case when col is null then 0 else col end
hawkming 2010-09-28
  • 打赏
  • 举报
回复
select isnull(col1,0) col1 from table
fpzgm 2010-09-28
  • 打赏
  • 举报
回复
select isnull(col1,0) col1 from tb
「已注销」 2010-09-28
  • 打赏
  • 举报
回复
[Quote=引用楼主 kvkensin9 的回复:]
请问怎么把视图的null转换为0?谢谢
[/Quote]

select isnull(ziduan,0) ziduan 
from tb

or

select coalesce(ziduan,0) ziduan
from tb

喜-喜 2010-09-28
  • 打赏
  • 举报
回复
select isnull(cast(col1 as int),0) col1 from tb
cjzm83 2010-09-28
  • 打赏
  • 举报
回复
coalesce(字段,0)
昵称被占用了 2010-09-28
  • 打赏
  • 举报
回复
select isnull(字段,0) as 字段
from tab

字段必须数字型
ws_hgo 2010-09-28
  • 打赏
  • 举报
回复
select isnull(col1,0) col1 from tb

22,302

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧