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 do an update using a sub select

Author  Topic 

kalwork
Starting Member

5 Posts

Posted - 2008-07-28 : 11:51:43
Here is my query psuedo:

update tab1
set col1=(select col2 from tab2 where tab2.a=tab1.a and tab2.b=tab1.c)
where tab1.d is not null

if tab2 has empty rows it gives an mutiple rows returned error

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-07-28 : 12:19:57
update tab1
SET col1 = col2
FROM
tab1
INNER JOIN
tab2
ON
tab1.a = tab2.a
and tab1.c = tab2.b --(tab2.c?)
WHERE tab1.d is not null

Jim
Go to Top of Page

kalwork
Starting Member

5 Posts

Posted - 2008-07-29 : 03:39:51
Thanks very much for this help JimF - Saved my Bacon and Sausages too!!
Go to Top of Page
   

- Advertisement -