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)
 compare two tables

Author  Topic 

eugz
Posting Yak Master

210 Posts

Posted - 2010-08-03 : 16:45:04
Hi All.

I need to compare two table by field CompName and update value in column Exist. If in Table2 column CompName has same data like in Table1 insert in column Exist Table2 value "Yes". How it to do?

Thanks.

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-08-03 : 16:49:02
[code]UPDATE a
SET a.Exist = 'Yes'
FROM Table2 a
INNER JOIN Table1 b on a.CompName = b.CompName[/code]
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-03 : 16:49:13
UPDATE t2
SET t2.[Exist] = 'Yes'
FROM Table2 AS t2
INNER JOIN Table1 AS t1 ON t1.CompName = t2.CompName


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-08-03 : 16:49:43



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

eugz
Posting Yak Master

210 Posts

Posted - 2010-08-03 : 17:26:56
Thanks for help.
Go to Top of Page
   

- Advertisement -