0

I have a product table. I have some empty rows. I want to fill these rows with an existing row. For example, if I have

Product
-----------------------------------
ID   Name  Desc  ---------------
1     A     A1   ---------------
2     B     B1   ---------------
3     C     C1   ---------------

I want to copy all the items of ID=1 into ID = 3 row.

Tried this but getting error, 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
Imran Qadir Baksh - Baloch
  • 32,612
  • 68
  • 179
  • 322

1 Answers1

1

You need to use alias - either DP or SP in UPDATE and not Products itself because it's ambiguous between the two.

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
Nenad Zivkovic
  • 18,221
  • 6
  • 42
  • 55