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
 Table update with values from another table

Author  Topic 

normannen
Starting Member

4 Posts

Posted - 2011-11-14 : 10:11:23
Hi.
Can anyone help me with this ?

I have 2 tables.
One is used to update the other one with.
I need to read from TableUpdate and change rank and add the increase in salary to TableMain.
And this is for all rows in that table.
It has to match each persons row and update it.

Have tried some examples, but failed.

TableMain
Name (Mike, John, Jack, etc)
Rank (1,2,3,4, etc)
Salary

TableUpdate
Name
RankNew (To replace the old one)
SalaryIncrease (A amount to be add to the ordinary salary).

Thanks in advance.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-14 : 10:24:09
[code]
UPDATE m
SET m.Rank = u.RankNew,
m.Salary = m.Salary + u.SalaryIncrease
FROM TableMain m
INNER JOIN TableUpdate u
ON u.Name = m.Name
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

normannen
Starting Member

4 Posts

Posted - 2011-11-14 : 10:52:23
Thanks, I'll try that...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-14 : 10:53:47
np...let us know if you face any issues

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -