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呵呵,这种是事后处理的,如果想在插入数据的时候就执行,可以在建表的时候计算设置计算列,也可以使用触发器。
楼主朋友,直接用一个语句就可以了. update 表名 set A=isnull(A,0)+ isnull(B,0)就可以实现您的要求了.
update tab set A=isnull(A,0)+ isnull(B,0) 如果2个字段都设置了非空,则update tab set A=A+B
这个最能满足你的要求
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呵呵,这种是事后处理的,如果想在插入数据的时候就执行,可以在建表的时候计算设置计算列,也可以使用触发器。
update 表名
set A=isnull(A,0)+ isnull(B,0)就可以实现您的要求了.