表Table1
里面有列A,B,C,D,E,F,G,H,I,JB,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
....有没有简单点的语句????

解决方案 »

  1.   

    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)
      

  2.   

    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
    ..
      

  3.   

    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
      

  4.   

    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...
      

  5.   

    本帖最后由 josy 于 2011-05-06 14:57:24 编辑
      

  6.   


    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.1update @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
      

  7.   

    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)