Adi Drumea

Monday, February 04, 2008

[SQL Server] Copy data between rows of the same table

How do you solve the problem of copying data from the same column between two existing rows of the same table, in Microsoft SQL Server 2000?

The answer is UPDATE ... FROM:

UPDATE tbl SET val = b.val
FROM tbl, tbl b
WHERE tbl.primaryKey=pk1 AND b.primaryKey=pk2


The syntax may seem a bit weird... but it works.

2 Comments:

  • Well written article.

    By Anonymous Anonymous, at 4:11 PM  

  • thanks, very nice article

    By Anonymous green one, at 12:23 PM  

Post a Comment

<< Home