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 - 2005-08-31 : 07:36:52
|
Kairn writes "I have created a table and imported data from another table to it. I need to update the existing data with values from another import but only need specific columns and am assuming a stored procedure is the way to go...IF I create a source table as well as destination(?). I have to compare the value in 6 columns to find the matching record in the destination, then update 5 of the other columns where source=dest. Finally, I need to sum, by row, the value in 3 of the columns and update another column to reflect it. All rows are unique in the destination. The source is a duplicate of them. Basically, the rows are identical aside from the values in the columns I want transferred. The rows must remain unique. I am a newbie and have no idea how to do this. Would you please submit a basic outline and I can fill in the rest?Thank-you very much for your time and expertise,Kairn" |
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2005-08-31 : 12:15:35
|
Okay, here's a template:UPDATE t1SET t1.Field1 = t2.Field1, t1.Field2 = t2.Field2, t1.Field3 = (t2.Field3 + t2.Field4 + t2.Field5)FROM DestTable t1 JOIN SourceTable t2 on t1.PKField = t2.PKFieldWHERE t1.Field9 = t2.Field9 ---------------------------EmeraldCityDomains.com |
|
|
|
|
|