求一条语句, 将表内某些为null的update成0

zuoxxx 2011-05-06 02:52:03
表Table1
里面有列A,B,C,D,E,F,G,H,I,J

B,C,E,F,H,J为demical类型
在有的数据行里,B,C,E,F,H,J中的某些为NULL

我希望将NULL的update成0

但是我不希望写成下面这样很多句子
update Table1 set B=0 where B is null
update Table1 set C=0 where C is null
update Table1 set E=0 where E is null
update Table1 set F=0 where F is null
....

有没有简单点的语句????
...全文
72 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rotel-刘志东 2011-05-06
  • 打赏
  • 举报
回复
update table1 B=(case when B is null then B=0 end),
C=(case when C is null then C=0 end),
E=(case when E is null then E=0 end),
F=(case when F is null then F=0 end)
叶子 2011-05-06
  • 打赏
  • 举报
回复

declare @table table
(B decimal(2,1),C decimal(2,1),E decimal(2,1),
F decimal(2,1),H decimal(2,1),J decimal(2,1))
insert into @table
select 1.1,1.2,1.4,1.5,1.9,2.1 union all
select null,3.2,null,9.1,null,9.1 union all
select 1.1,null,1.3,1.1,null,null union all
select 1.5,null,null,null,1,2.1

update @table set B=isnull(B,0),
C=isnull(C,0),E=isnull(E,0),F=isnull(F,0),H=isnull(H,0),J=isnull(J,0)
select * from @table
百年树人 2011-05-06
  • 打赏
  • 举报
回复
update table1
set
b=isnull(b,0),
c=isnull(c,0),
e=isnull(e,0),
f=isnull(f,0),
h=isnull(h,0),
j=isnull(j,0)
SQL77 2011-05-06
  • 打赏
  • 举报
回复
UPDATE TB1 SET B=CASE WHEN B IS NULL THEN 0 ELSE B END,C=...
FROM TB1 WHERE B IS NULL OR C IS NULL...
Rotel-刘志东 2011-05-06
  • 打赏
  • 举报
回复
update table1 set B=0,set C=0,E=0,F=0
where B is null and C is null and E is null and F is null
rucypli 2011-05-06
  • 打赏
  • 举报
回复
update tb1 set B=case when B is null then 0 end,
c=case when c is null then 0 end,
d=case when d is null then 0 end
..

快溜 2011-05-06
  • 打赏
  • 举报
回复
update Table1 set B=(case when B is null then 0 else B end),
C=(case when C is null then 0 else C end),
E=(case when E is null then 0 else E end),
F=(case when F is null then 0 else F end)

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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