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)
 check if data exists in second database

Author  Topic 

PurpleSun
Yak Posting Veteran

50 Posts

Posted - 2007-05-21 : 11:33:26
Hi All,

I have two different databases DB1 and DB2.
In DB1 there is a table T1 with the column RecID [int] [primary]
In DB2 there is a table T2 with the same column.
For every record in DB1 T1 i need to check if RecID exists
in DB2 T2.

What's the best way of doing this?

Thanks.

X002548
Not Just a Number

15586 Posts

Posted - 2007-05-21 : 11:37:11
SELECT * FROM db1.dbo.table a
WHERE EXISTS (SELECT * FROM db2.dbo.table b
WHERE a.RecID = b.RecID)

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

PurpleSun
Yak Posting Veteran

50 Posts

Posted - 2007-05-21 : 11:41:42
Thanks Brett.
That's exactly what I need.
Go to Top of Page
   

- Advertisement -