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
 General SQL Server Forums
 New to SQL Server Programming
 UPDATE THE TABLES

Author  Topic 

Patyk
Yak Posting Veteran

74 Posts

Posted - 2014-10-17 : 16:07:11
I need to update this old table with new data
105 FIELD 2015 15190 17516 13231 8607 6582
105 STORE 2015 35855 30647 29781 27642 24784
105 ULT 2015 120291 23015 26995 33918 22100
columns custId Type Year month1 month2 month3 month4 month5

My new table looks the same.

Primary Key CustId Type Year

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-10-17 : 16:10:38
I'm unclear what you are asking. Show us sample data for the old table and what it should look like after the update.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Patyk
Yak Posting Veteran

74 Posts

Posted - 2014-10-17 : 16:18:45
I need to update the following table (here is the sample) with new Monthly Budgets are are in another table with New Data Columns in both tables are the same. Primary Key CustId Type Year
custId Type Year month1 month2 month3 month4 month5
105 FIELD 2015 15190 17516 13231 8607 6582
105 STORE 2015 35855 30647 29781 27642 24784
105 ULT 2015 120291 23015 26995 33918 2210
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-10-17 : 16:21:32
You already provided that data. It didn't make it clear. Please read this article for how to post a clear question with sample data so that we can help you: http://www.sqlservercentral.com/articles/Best+Practices/61537/

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Patyk
Yak Posting Veteran

74 Posts

Posted - 2014-10-17 : 16:36:58
Sorry I just need to update the data above with new values from my new table
105 FIELD 2015 15190 1000 13231 5894 6582
105 STORE 2015 5000 30647 29781 27642 5268
105 ULT 2015 120291 23015 200 33918 3654

I need to find the matching records where CustId, StoreId, and Year are the same and update values for Month1, Month2, Month3,Month4, and Month5


My Master Budget Table needs to be updated with new values .

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-10-17 : 16:47:43
I'll provide an example.

UPDATE t1
SET col5 = t2.col5, col6 = t2.col6
FROM table1 t1
JOIN table2 t2 ON t1.col1 = t2.col1

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -