Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Update Automation

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-12-26 : 10:41:29
David writes "I have an "UPDATED" table that is a duplicate of an "ORIGINAL" table. "UPDATED" will be purged every night and updated data will be imported. I need to set up an automated process to update the "ORIGINAL" table with any changed values in the "UPDATED" table. I have a "SEQUENCE" column that will always be the same between these tables which will be used to match up the rows.

Example:


"ORIGINAL" TABLE
SEQUENCE NAME AGE PHONE
-----------------------------------------------------
1 Fred 30 (123)456-7890
2 Barney 29 (234)567-8901
3 Casper 28 (345)678-9012

"UPDATED" TABLE
SEQUENCE NAME AGE PHONE
-----------------------------------------------------
1 Fred 31 (098)765-4321
2 Barney 30 (987)654-3210
3 Casper 29 (876)543-2109


Is there a better way of doing this than my beginner TSQL below?

update ORIGINAL set AGE = UPDATED.AGE from UPDATED where ORIGINAL.SEQUENCE = UPDATED.SEQUENCE

update ORIGINAL set PHONE = UPDATED.PHONE from UPDATED where ORIGINAL.SEQUENCE = UPDATED.SEQUENCE

I have a lot more fields than this example and my multiple statements for each field seem, somewhat, unnecessary. :\"

mfemenel
Professor Frink

1421 Posts

Posted - 2002-12-26 : 10:50:54
You can do this all as one statement provided you're always using the same selectin criteria, Original.Sequence=Updated.Sequence

Try this:
update ORIGINAL set AGE = UPDATED.AGE,Phone=Updated.Phone
from UPDATED where ORIGINAL.SEQUENCE = UPDATED.SEQUENCE

Mike
"oh, that monkey is going to pay"
Go to Top of Page
   

- Advertisement -