使用SQL Query,如何更新此表
pkey ColA ColB ColC
---- ---- ---- ----
ABC1 appl pine orng
BOPQ pine appl orng
PLKQ orng appl pine
从此表中获取ColC值
pkey ColA ColB ColC
---- ---- ---- ----
ABC1 xbcs qqqq STRA
BOPQ asdf retf BERR
PLKQ 32q4 xcvv YTAR
MLAO iasp xclk qppe
获取此更新结果
pkey ColA ColB ColC
---- ---- ---- ----
ABC1 appl pine STRA
BOPQ pine appl BERR
PLKQ orng appl YTAR
答案 0 :(得分:3)
尝试这种方式:
update This_table
set This_table.ColA = C.ColA,
This_table.ColB = C.ColB
from ColC C
where C.pkey = This_table.pkey
答案 1 :(得分:0)
还有一个选项
UPDATE t1
SET t1.ColC = t2.ColC
FROM dbo.test1 t1 JOIN dbo.test2 t2 ON t1.pkey = t2.pkey
SQLFiddle上的演示