SQL Server Update with a join


http://www.ruslansivak.com/index.cfm/2007/1/11/SQL-Server-Update-with-a-join

Have you ever needed to update one table based on the contents of another table? The way to do it is with aliases.

update t1 set t1.field=replace(t1.field, t2.field1, t2.field2) from table1 t1 inner join table2 t2 on t1.primaryKey=t2.foreignkey
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: