October 07, 2010

Join in Update/Delete Statement in SQL Server

Update Statement
UPDATE t1
SET t1.TargetCol1 = t2.SourceCol1,
t2.TargetCol2 = t2.SourceCol2
FROM Table1 AS t1
INNER JOIN Table2 AS t2 ON t2.PrimaryCol = t1.PrimaryCol

Delete
DELETE TB1 FROM Table1 TB1 INNER JOIN StagingTable ON Table1.Field2 = StagingTable.Field2

No comments:

Post a Comment