一个表中一个字段插入另外一个字段
2个字段都是同类型INT
如果字段A值等于0就直接把字段B值插入A
如果A字段值不等于0 就和B字段值相加插入.请教如何写,谢谢.

解决方案 »

  1.   

    >.<我只会简单的,触发器就不会了。。高手帮帮忙吧
      

  2.   

    update 表名 set a=a+b
      

  3.   

    update table set if A=0 then A=B else A=A+B
      

  4.   

    update 表名 set a=a+b
      

  5.   

    update 表名 set a=isnull(a,0)+b 
      

  6.   

    update 表名 set a=isnull(a,0)+b 
      

  7.   

    update 表名 set a=isnull(a,0)+b
    这个最能满足你的要求
      

  8.   

    update 表名 set a=isnull(a,0)+b 
      

  9.   


    create table t(a int ,b int,c int )goInsert into  t (a,b)
    select 1,2 union all
    select 2,2 union all
    select 0,4 go
    update t set c=isnull(a,0)+b
    go
    select * from  t呵呵,这种是事后处理的,如果想在插入数据的时候就执行,可以在建表的时候计算设置计算列,也可以使用触发器。
      

  10.   

    楼主朋友,直接用一个语句就可以了.
    update 表名
        set A=isnull(A,0)+ isnull(B,0)就可以实现您的要求了.
      

  11.   

    update tab set A=isnull(A,0)+ isnull(B,0) 如果2个字段都设置了非空,则update tab set A=A+B
      

  12.   

    用update就可以了,楼主需要多看看基础语法方面的书,这个问题很简单的