Created
February 1, 2018 21:58
-
-
Save aroder/803b10fa5e985190693c65069d9e0461 to your computer and use it in GitHub Desktop.
Diff 2 tables from different databases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH A AS ( | |
SELECT * | |
FROM OPENROWSET('SQLNCLI', 'Server=<SERVERA>;Database=CADIS;Trusted_Connection=yes;', 'select top 10 * from <TABLE>') | |
), | |
B AS (SELECT * FROM <TABLE>), | |
A_ONLY AS ( | |
SELECT TOP 10 * FROM A | |
EXCEPT | |
SELECT TOP 10 * FROM B | |
), | |
B_ONLY AS ( | |
SELECT TOP 10 * FROM B | |
EXCEPT | |
SELECT TOP 10 * FROM A | |
) | |
SELECT '<INSTANCEA>' AS SOURCE, '<TABLE>' AS TABLE_NAME, * FROM A_ONLY | |
UNION | |
SELECT '<INSTANCEB>' AS SOURCE, '<TABLE>' AS TABLE_NAME, * FROM B_ONLY | |
ORDER BY CADIS_ID, SOURCE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment