Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a select statement in a table in DB1 and using a linker server in SQL Server 2014 to connect to offsite database DB2.

Now i have some columns which have the same data for example, i have the following columns in both tables:

- Filename
- Location
- ID

However, the ID's in the tables are not the same but the filenames are the same. I imported the data from DB2 to DB1 but some files did not. So i want to compare the two tables to see what i have not copied across from DB2 to be copied across to DB1.

I m not sure how to do a compare using the linked server. Whats the best way to go about this?

Thanks in advance
Posted

1 solution

Several ways of writing a query to do this. Perhaps simplest is to use the except SQL operator

Q1 except Q2 will return all rows in Q1 but excluding those in Q2. Think of it as Q1 minus Q2.

Thus a query of
select Filename from DB1..table except select Filename from DB2..table
should give you want you want.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900