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 TABLE from SUBQUERY

Author  Topic 

jayram11
Yak Posting Veteran

97 Posts

Posted - 2010-07-15 : 09:14:14
Hello ALL,
i have this query which pulls the data i need

select a.pr_no, a.wi, b.ho_wi from COUNTY as a
inner join HOSPITAL as b
on a.pr_no = b.ho_num
where year(a.eff_end) = 2045 and year(b.ho_eff_end) = 2045 and a.wi <> b.ho_wi

i want to update the b.ho_wi with a.wi wherever they are different for the years in 2045 in table HOSPITAL
Thanks


vision.v1
Yak Posting Veteran

72 Posts

Posted - 2010-07-15 : 10:21:25
quote:
Originally posted by jayram11

Hello ALL,
i have this query which pulls the data i need

select a.pr_no, a.wi, b.ho_wi from COUNTY as a
inner join HOSPITAL as b
on a.pr_no = b.ho_num
where year(a.eff_end) = 2045 and year(b.ho_eff_end) = 2045 and a.wi <> b.ho_wi

i want to update the b.ho_wi with a.wi wherever they are different for the years in 2045 in table HOSPITAL
Thanks







Try below code:


UPDATE
a
SET
b.ho_wi = a.wi
from COUNTY as a
inner join HOSPITAL as b
on a.pr_no = b.ho_num
where year(a.eff_end) = 2045 and year(b.ho_eff_end) = 2045 and a.wi <> b.ho_wi
Go to Top of Page

jayram11
Yak Posting Veteran

97 Posts

Posted - 2010-07-15 : 18:34:49
thanks it worked..
update a should be update b
Go to Top of Page
   

- Advertisement -