SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Simple SQL to update specific columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 08/31/2005 :  07:36:52  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
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

USA
3246 Posts

Posted - 08/31/2005 :  12:15:35  Show Profile  Visit AjarnMark's Homepage  Reply with Quote
Okay, here's a template:
UPDATE t1
SET
  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.PKField
WHERE 
  t1.Field9 = t2.Field9



---------------------------
EmeraldCityDomains.com

Edited by - AjarnMark on 08/31/2005 12:16:19
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000