Re: finding mismatched rows between identical tables based on 2 or more cols
Posted by Plamen Ratchev on 06/10/07 03:13
Here are two different approaches:
-- SQL Server 2005 only.
SELECT ColA, ColB FROM RS_A
EXCEPT
SELECT ColA, ColB FROM RS_B;
-- SQL Server 2000.
SELECT ColA, ColB FROM
( SELECT 'A' AS Source, ColA, ColB
FROM RS_A
UNION ALL
SELECT 'B' AS Source, ColA, ColB
FROM RS_B ) AS T
GROUP BY ColA, ColB
HAVING COUNT(*) = 1 AND MIN(Source) = 'A'