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 2008 Forums
 Transact-SQL (2008)
 Update a value from another table

Author  Topic 

venkatch786
Starting Member

8 Posts

Posted - 2010-08-20 : 08:06:54
Hi,
I have table1 having OrgID and Value1 columns
and another table2 having OrgID and districts columns
one more table3 having value2 and districts columns.

I want to Update table1 value1 with table3 value2 for each districts for same OrgID

Here OrgID is Unique and districts are duplicate

Thanks in Advance

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-08-20 : 08:19:53
UPDATE table1 SET value1 = a.value2
FROM table1 t1
INNER JOIN
(
SELECT distinct orgID, districts, value2 FROM table2 t2 INNER JOIN
table3 t3 ON t2.districts = t3.districts
) a ON t1.OrgID = a.OrgID


Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-20 : 08:24:16
quote:
Originally posted by vaibhavktiwari83

UPDATE t1SET value1 = a.value2
FROM table1 t1
INNER JOIN
(
SELECT distinct orgID, districts, value2 FROM table2 t2 INNER JOIN
table3 t3 ON t2.districts = t3.districts
) a ON t1.OrgID = a.OrgID


Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER


You need to use alias name



Madhivanan

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

- Advertisement -