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 rows between 2 tables

Author  Topic 

Jim Beam
Posting Yak Master

137 Posts

Posted - 2010-10-12 : 06:21:56
Good morning fellow DB denizens,

I need to compare 2 tables on separate servers to see if all the data in dbsrvr2.queues2.outqueue2c exists in dbsrvr1a.archive.outqueue1009 via the common MsgID column.

Here's what I've got so far...

Select Count (*)
from OutQueue2C
Where MsgID in (Select MsgId from dbSrvr1a.archive.outqueue1009)

Obviously this doesn't link the servers, nor does it perform a full check to see whether all MsgID's that exist outqueue2c also exist in Outqueue1009, so the query fails.

Thanks,

Jim

Kristen
Test

22859 Posts

Posted - 2010-10-12 : 06:48:26
"Obviously this doesn't link the servers"

Should do. If you have a linked server configured then you should be able to do

SELECT TOP 10 MsgId from LinkedServerName.DatabaseName.dbo.outqueue1009

"dbo" is the default schema, but you'll need to change that if you the target table on the remote is using a different schema
Go to Top of Page

Jim Beam
Posting Yak Master

137 Posts

Posted - 2010-10-12 : 07:37:45
My bad Kristen, thanks!!
Go to Top of Page
   

- Advertisement -