Tuesday, September 29, 2009

join in SQL update statement ( update with match two tables)

join in SQL update statement

I had to update value from a staging table( this might be a temp table )
into another database table. Here is how I did it using a inner join in
the Update statement.



UPDATE Table1

SET Table1.Field1 = StagingTable.Field1

FROM Table1 INNER JOIN StagingTable ON Table1.Field2 = StagingTable.Field2



You can also add a where clause to this SQL:



WHERE StagingTable.Field3 IS NOT NULL

No comments:

Post a Comment