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.
Author |
Topic |
collie
Constraint Violating Yak Guru
400 Posts |
Posted - 2013-08-03 : 08:29:42
|
Hi,I have 2 tables on different servers connected with linked server.I need to compare the 2 tables. I need to find policies that exist in one table but not the other and vice versa.My team leader suggested creating a new table and filling in the table with the policies from both servers and adding 2 another 2 columns : ExistTB1 ExistsTB2. What is the best way to compare? No 3rd party tools pls. Thanks |
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2013-08-06 : 14:15:20
|
you can write a cross query using linked server.eg:select policy from linkedserver1.dbname.dbo.table1 where policy not in(select policy from linkedserver2.dbname.dbo.table2)and viceversa.mohammad.javeed.ahmed@gmail.com |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-08-07 : 01:29:28
|
why two linkedserver? you just need to run from one of the server and use linkedserver to connect to the other.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
AlexTheDeveloper
Starting Member
2 Posts |
Posted - 2013-08-07 : 04:20:37
|
How big the tables are? You don't need to copy table from another server if let's say it contains less than 5000 records.the following query will give you missing policies in server A.select a.* from TableInA a LEFT JOIN LinkedServerB.TableInB b on a.PolicyId = b.PolicyId (use your matching key here) WHERE b.PolicyId IS NULLfor missing policies in B - use RIGHT JOIN.Regardswww.ssmsaddin.com best free addin for SQL Server Management Studio 2008 2012 |
 |
|
|
|
|