Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update from another Table

Status
Not open for further replies.

btt423

Programmer
Jan 28, 2002
31
US
I have a table that is an extract from our personnel system. I have taken that table and split it up into several other tables based on the application that I'm building. One of the tables is contact_info.

In contact_info, I need to update some of the fields in each record if the record has not been updated in the last 2 weeks. The update will come from the table holding the extract information (which is being updated every evening).

How should I go about doing this???

Thanks, Brinson
 
Update contact_info
set field1 = B.some_field, ...
FROM contact_info A Inner Join extract_table B
ON A.field = B.field
WHERE A.update_field < DATEADD(day, -14, getdate() )
 
This will update one field... is there anyway to update 10 or so at one time, or will I just need to execute 10 of these update statements?

Thanks for your help!
 
balves included &quot;, ...&quot; in his example. That means you can update multiple columns. You simply list the columns in the place of the ...!

Update contact_info
set field1 = B.some_field,
field2 = B.some_field2,
...,
field10 = B.some_field10
FROM contact_info A Inner Join extract_table B
ON A.field = B.field
WHERE A.update_field
< DATEADD(day, -14, getdate() ) Terry L. Broadbent - Salt Lake City, UT
Home of the 2002 Winter Olympics (Feb 8-24)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top