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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to update table value from another table

Author  Topic 

snow12
Yak Posting Veteran

74 Posts

Posted - 2011-01-20 : 10:51:15
Hello:

I have table a and would like update table a whose values from table b, but not update all rows at table a. Only update record ID in table a match record ID in tableC.

Here is my query

update a
set a.Desc = b.Desc,
a.Value = b.Value
from TableA a, TableB b
where a.name = b.name
and a.ID = b.ID
and a.ID in ( select ID from TableC)

I only have 12 a.ID match TableC, but above query update whole TableA.
How to only update 12 record at TableA from TableB?

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-20 : 13:52:53
update a
set a.Desc = b.Desc,
a.Value = b.Value
from TableA a
join TableB b
on a.name = b.name and a.ID = b.ID
and exists(select * from tableC as c where c.ID = a.ID)



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

snow12
Yak Posting Veteran

74 Posts

Posted - 2011-01-20 : 16:13:13
Thank you very much!
Go to Top of Page
   

- Advertisement -