第1个回答 2012-04-07
mssql这么写:
update TABLE1
set
a=isnull(TABLE2.a,TABLE1.a),
b=isnull(TABLE2.b,TABLE1.b),
c=isnull(TABLE2.c,TABLE1.c),
d=isnull(TABLE2.d,TABLE1.d),
e=isnull(TABLE2.e,TABLE1.e),
from
TABLE1,TABLE2
where TABLE1.account=TABLE2.account
第2个回答 2012-04-05
要用函数比较麻烦 给你个思路
1.遍历table2 判断一行不为空值的字段
2.更新这些字段到table1
update 的时候 set 值的时候判断给的值是不是空 如果是 就给原值也就是table1的值 否则就更新为table2的值.
第3个回答 2012-04-05
----oracle的写法
update table1 t1
set (a,b,c,d,e) = (select nvl(t2.a,t1.a),nvl(t2.b,t1.b),nvl(t2.c,t1.c),nvl(t2.d,t1.d),nvl(t2.e,t1.e)
from table1 t2 where t1.account = t2.account);
第4个回答 2012-04-18
UPDATE TABLE1
SET table1.a=CASE WHEN table1.a=t2.a THEN table1.a ELSE ISNULL(t2.a,table1.a) END ,
table1.b=CASE WHEN table1.b=t2.b THEN table1.b ELSE ISNULL(t2.b,table1.b) END ,
table1.c=CASE WHEN table1.c=t2.c THEN table1.c ELSE ISNULL(t2.c,table1.c) END ,
table1.d=CASE WHEN table1.d=t2.d THEN table1.d ELSE ISNULL(t2.d,table1.d) END ,
table1.e=CASE WHEN table1.e=t2.e THEN table1.e ELSE ISNULL(t2.e,table1.e) END
FROM table2 t2
WHERE table1.accout=t2.accout本回答被提问者采纳