Wednesday 8 July 2009

Updating an SQL Table using a join

Today I needed to update one of the tables in my database replacing the value in one field with a derived value from another table. A quick search on the internet turned up this useful post from Ben Nadel


Essentially the statment required is as follows:

UPDATE A
SET DestinationField = B.SourceField
FROM TableToUpdate A
INNER JOIN TableToReadFrom B
ON A.JoinKey = B.JoinKey

No comments: