UPDATE SET FROM WHERE 续
UPDATE B
SET B.InDate=a.InDate,B.EditDate=A.EditDate,B.OperateDate=A.OperateDate
FROM (SELECT T.InDate,T.EditDate,T.OperateDate,T.SONumber FROM SOTracking AS T WITH(NOLOCK)
WHERE T.operation=130 and T.SONumber in(111,222,333)) AS A
INNER JOIN SOTracking AS B ON B.SONumber=a.SONumber
WHERE Operation=60
-------------------------------------------------------------------------------------------
;with so_date as
(
SELECT InDate,EditDate,OperateDate,SONumber FROM SOTracking WITH(NOLOCK)
WHERE operation=130 and SONumber in(111,222,333)
)
UPDATE A
SET A.InDate=t.InDate,A.EditDate=t.EditDate,A.OperateDate=t.OperateDate
FROM so_date AS T INNER JOIN SOTracking as A ON A.SONumber=t.SONumber
WHERE A.Operation=60
需要注意的是:FROM需要把更新的表和关联的表都写在这里。其实主要就是UPDATE FROM 的用法
比较喜欢自己写的第二个方法,看着清晰,还是自己想出来的。嘻嘻~~~~~~~终于知道WITH杂用了。