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.
| 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" TABLESEQUENCE NAME AGE PHONE-----------------------------------------------------1 Fred 30 (123)456-78902 Barney 29 (234)567-89013 Casper 28 (345)678-9012"UPDATED" TABLESEQUENCE NAME AGE PHONE-----------------------------------------------------1 Fred 31 (098)765-43212 Barney 30 (987)654-32103 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.SEQUENCEupdate ORIGINAL set PHONE = UPDATED.PHONE from UPDATED where ORIGINAL.SEQUENCE = UPDATED.SEQUENCEI 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.SequenceTry this:update ORIGINAL set AGE = UPDATED.AGE,Phone=Updated.Phonefrom UPDATED where ORIGINAL.SEQUENCE = UPDATED.SEQUENCEMike"oh, that monkey is going to pay" |
 |
|
|
|
|
|