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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Table from Second Table

Status
Not open for further replies.

SuperComputing

IS-IT--Management
Oct 11, 2007
57
0
0
US
Forgive me if I've posted this in the wrong forum...

We have a Database 'CP' with several tables, one of which is 'Customers'. We went into the 'Customers' table and made changes to both the 'SalesRep' column and the 'Category' column. Now, 45 days later, they want the changes made to the 'SalesRep' column to be undone.

I have a backup of the table before any changes were made and I have restored it to 'CustomersOLD' and have gone in and updated the 'Category' column and left the 'SalesRep' column alone. However, the current table has had 300+ new customers added and several hundred of the rows of the existing customers have been modified. I can't simply import the new customers into the old table and replace.

I don't know if the syntax exists, can I combine the 2 tables, based on the 'CustomerNumber' column, and update the existing 'SalesRep' column with the data that is in the 'CustomersOLD' table, 'SalesRep' column?

UPDATE Customers SET 'SalesRep' = 'CustomersOLD.SalesRep' WHERE 'Customers.CustomerNumber' = 'CustomersOLD.CustomerNumber'

Since the 'CustomerNumber' is incremental, do I need to run a FOR loop?

Thanks for all of your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top