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)
 update tableA on the basis of tableB

Author  Topic 

nomiansari
Starting Member

2 Posts

Posted - 2008-07-22 : 13:16:06
Hi friends

am stuck at some point in MS SQL Server 2005 as am new to SQL.
Scenerio: I have two tables, let tableA & tableB. These can be joined on tableA.id = tableB.id. Am trying to update tableA.salary for all id's for which tableB.grade = 'A' . am runnning the following query

update tableA
set tableA.salary = xxxxxx
where exists (select tableA.id from tableA join tableB on tableA.id = tableB.id where tableB.grade = 'A')

What its actually doin is updating all the records regardless of the EXIST condition i-e it didn't update only the reqired rows but all. I have tried changing the SELECT statement like using * or other column names but in vain. Am I wrong at writing query or there exists some else solution to my case?

I appreciate ur responses

thanks
Noman

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-22 : 13:17:42
update ta
set ta.salary=xxxx
from tableA ta
iner join tableB tb
on ta.id = tb.id
where tb.grade='A'
Go to Top of Page

nomiansari
Starting Member

2 Posts

Posted - 2008-07-22 : 13:40:27
thanks friend :) it worked just as I wannit
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-22 : 13:43:30
you're welcome glad that i could help you out
Go to Top of Page
   

- Advertisement -