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 Query

Author  Topic 

sudha12345
Starting Member

47 Posts

Posted - 2009-08-28 : 09:19:38
I has two tables as below

Temp
ID Name
1 System1
2 System2
3 NULL
4 System4

Temp1

ID Name
3 System4

i wrote an Update query to update the Name of Temp Table with the Name of Temp1 Table (The Name NULL has to be updated with System4 by aking it from Temp1)

I wrote a query like

update temp set name = (select name from temp1 where temp.id =temp1.id)

But it is Updating all the 4 rows instead on only 1 row

can anyone correct the Query?


Sudhakar

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-28 : 09:27:12
update t
set name=t1.name
from temp as t inner join temp1 as t1
on t.id=t1.id and t.name is null

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -