我有一张产品表。我有一些空行。我想用现有行填充这些行。例如,如果我有
Product
-----------------------------------
ID Name Desc ---------------
1 A A1 ---------------
2 B B1 ---------------
3 C C1 ---------------
我想将ID = 1的所有项目复制到ID = 3行。
试过这个,但得到错误,Ambigious
UPDATE [Products]
SET DP.[Name] = SP.Name
,DP.[Desc] = SP.DESC
FROM [Products] DP
INNER JOIN [Products] SP ON SP.ID = 3
WHERE DP.ID = 1
答案 0 :(得分:1)
您需要使用别名 - UPDATE中的DP或SP,而不是产品本身,因为它们之间不明确。
UPDATE DP
SET DP.[Name] = SP.Name
,DP.[Desc] = SP.[DESC]
FROM [Products] DP
INNER JOIN [Products] SP ON SP.ID = 3
WHERE DP.ID = 1