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
 General SQL Server Forums
 New to SQL Server Programming
 Update single table on basis of joins two tables.

Author  Topic 

hspatil31
Posting Yak Master

182 Posts

Posted - 2012-04-24 : 05:57:06
Dear All,

I want to update ColumnC from Table1. On the basis,
CalumnA and ColumnB should be match and then update ColumnC in Table1 from the ColumnC value from Table2.

Can anybody please tell me the SQL statement for this ?

Table1:

ColumnA ColumnB ColumnC

Table2:

ColumnA ColumnB ColumnC

Thanks and Regard's
Harish Patil

vinu.vijayan
Posting Yak Master

227 Posts

Posted - 2012-04-24 : 06:35:06
Please post some sample data so that we can understand what you're requirement is.
What do you mean by "On the basis, CalumnA and ColumnB should be match"?
Which "CalumnA and ColumnB" are you talking about??...The ones in Table1 or the ones in Table2 or do you want to compare the columns in both tables??....

Please be a more precise about your requirement and please post some sample data.

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-04-24 : 07:00:39
update t1
set ColumnC = t2.ColumnC
from Table1 as t1
join Table2 as t2 on t2.ColumnA = t1.ColumnA and t2.ColumnB = t1.ColumnB



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-24 : 21:34:32
i hope the relationship between tables is 1- to -1

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -