Comparing Database Records in T-SQL

NigelRocks
NigelRocks used Ask the Experts™
on
Experts,

Let's say the records between two tables have fields that are in the same order, etc.  So, both tables have Field1, Field2, Field3, Field4, etc.

I want to find out which fields have different content between tables?  So if the content of Field1 in table1 is different from Field1 Table2, I want that field name displayed.  How would I do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Database Consultant
Top Expert 2009
Commented:
SELECT CASE WHEN a.Filed1 <> b.Field1 THEN 'Field1' ELSE NULL  END Filed1,
CASE WHEN a.Filed2 <> b.Field2 THEN 'Field2' ELSE NULL  END Filed2

FROM urTab1 a inner join urTable2 b on a.Key = b.key

Author

Commented:
OK, but I want to make this dynamic so I can loop through all the fields in the first table and find its match in the second.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial