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 * Clms from a 2nd tbl in one step 1

Status
Not open for further replies.

Idokyoku2

Technical User
May 16, 2004
57
US
How can I update tbl1 from tbl2 (both having the exact same structure) all in one step? I can do it a column at a time, but can't quite seem to nail it down all at once.

IDNum, Company, Contact, Addr2, Addr1, City, State, Zip, Zip4 on both with same datatypes.

David
 
If you are replacing all of the data, then the easiest way is to delete them from tbl1 based upon an inner join of the two tables on IDNum. Then add all of them. That's the easiest way but not necessarily the best way.
If IDNum is a clustered index, then I'd do the Update using the same inner join. Do you need more help?
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Point taken, but would you mind giving me the update?
 
Code:
[Blue]UPDATE[/Blue] A
   [Blue]SET[/Blue] Company[Gray]=[/Gray]B.Company[Gray],[/Gray] Contact[Gray]=[/Gray]B.Contact[Gray],[/Gray] etc.
   [Blue]FROM[/Blue] TableA A [Blue]INNER[/Blue] [Gray]JOIN[/Gray] TableB B
   [Blue]ON[/Blue] A.IDNum[Gray]=[/Gray]B.IDNum
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Nuts!!! I should have thought of that! I've been using virtually the same thing for one column.

Greatly appreciated.

David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top