update a set a.a2=isnull(b.b2,a.a2) from a left join b on a.a1=b.b1
表A ID,数量,金额,日期,一致否 表B ID,数量,金额,日期,一致否当满足条件 A.id=B.id and A.数量=B.数量 and A.金额=B.金额 and A.日期=B.日期 时,用一条语句同时更新 A.一致否=1 和B.一致否=1
写2条语句,一个update只能写一个表
create procedure my_proc as begin update A set A2 = ... from A , B where A.A1 = B.B1 update B set B2 = ... from B , A where B.A1 = A.B1 end goexec my_proc
set a.a2=isnull(b.b2,a.a2)
from a left join b
on a.a1=b.b1
表B ID,数量,金额,日期,一致否当满足条件
A.id=B.id and A.数量=B.数量 and A.金额=B.金额 and A.日期=B.日期
时,用一条语句同时更新
A.一致否=1 和B.一致否=1
create procedure my_proc
as
begin
update A set A2 = ... from A , B where A.A1 = B.B1
update B set B2 = ... from B , A where B.A1 = A.B1
end
goexec my_proc
update A set A2 = ... from A , B where A.A1 = B.B1;update B set B2 = ... from B , A where B.A1 = A.B1
注意分号分割