SQL Server中動態地利用join來做update,如下例中,我們要把B Table中的Name欄位update為A Table中對應的Id的Name欄位的值:
A Table
-------------------------
Id Name
-------------------------
1 abc
2 cde
3 efg
4 stu
5 xyz
-------------------------
B Table
-------------------------
Id Name
-------------------------
1 a1
2 b1
3 c1
4 d1
5 e1
-------------------------
update B set name = a.name from B b inner join A a on a.id = b.id
參考:http://stackoverflow.com/questions/11247982/update-multiple-rows-using-select-statement
沒有留言:
張貼留言