[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 421
  • Last Modified:

T-SQL: creating list of columns that don't match

Hi,

I am comparing data in 2 identical tables and retuning rows that have columns with wrong data.
In the moment I am selecting all columns and have to look through all of them to find not matching ones.
I'd like to create additional column that will have a list of not matching columns names.

Any ideas how to implement it in sproc?
What are other choices?
0
quasar_ee
Asked:
quasar_ee
2 Solutions
 
Aneesh RetnakaranDatabase AdministratorCommented:
did you try red-gate data compare tool,  trial version has full capabilities and works for 14 days
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
How many columns are we talking about?

afaik the only way to pull this off is..
-- TableA, not in TableB
SELECT a.Col1 -- add every column a here
FROM TableA a
   LEFT JOIN TableB b ON a.id = b.id AND -- add every dang a.column = b.column we're talking about here
WHERE b.Col1 IS NULL

-- TableB, not in TableA
SELECT b.Col1 -- add every column b here
FROM TableB b
   LEFT JOIN TableA a ON b.id = a.id AND -- add every dang b.column = a.column we're talking about here
WHERE a.Col1 IS NULL

Open in new window


btw does 'Wrong' mean 'not matches'?
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now