SQL: update data from multiple table’s join

Sometimes, you need to update a table field with value from other tables.
What if an UPDATE with data from a SELECT&JOIN ?
Well, it’s possible with just a simple UPDATE ! 🙂

For example, update campaign data with values from its agent, then SQL statement could be like this:

UPDATE Campaigns
SET Campaigns.FieldA = Agents.FieldB
FROM Campaigns JOIN Agents ON Campaigns.IDAgent = Agents.ID

This SQL statement is very usefull preparing data for report. 😉

source: UPDATE on MSDN

Technorati tags: SQL Server, SQL, UPDATE
Advertisements

Tags:

One Response to “SQL: update data from multiple table’s join”

  1. UPDATE – FROM … again « a developer’s breadcrumb Says:

    […] already told about UPDATE statement with FROM clause, here. Have you already used with real-time generated data in SET clause ? Something with GETDATE() o […]

Leave a Reply

Fill in your details below or click an icon to log in:

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: