日期:2014-05-18 浏览次数:20497 次
update b set m = x from a join b on a.x = b.x and a.y = b.y
------解决方案--------------------
use DBTest go if OBJECT_ID('A') is not null drop table A go create table A ( X int, Y int ) go insert into A select 1,1 union all select 2,2 create table B ( X int, Y int, M int, N int ) go insert into B select 1,1,11,11 union all select 2,2,22,22 UPDATE B SET M=A.X FROM A INNER JOIN B ON A.X=B.X AND A.Y=B.Y
------解决方案--------------------
UPDATE B SET M=(SELECT X FROM A ta WHERE ta.X=tb.X AND ta.Y=tb.Y) FROM B tb