-3

I have to find out the name of columns which have different data in a source except target query.

Currently when I am executing a Source except Target query, Even if there is only one column value is different, it's returning entire row. My requirement is to find out names of such columns which have data difference and put them into a separate table.

For example if I have a table as below:

Select * from A;

Col1    Col2   Col3    Col4
1        A     India   Delhi
2        A     US      Newyork

when I Query:

Select * from A where Col1=1
except
select * from A where Col1=2

It will display:

Col1    Col2   Col3    Col4
1        A     India   Delhi

However I need to populate Col1 (Key field) value and Col3,Col4 names(Column names, which were not found to be same at the time of except query execution) into a new table.

Shashank
  • 11
  • 1

1 Answers1

0

I think your approach has a conceptual bug. Assuming your tables are

Col1  Col2
----  ----
A     A   
B     B   
C     C   

Col1  Col2
----  ---- 
A     A   
B     C   
C     B   

If you use "SELECT Expect", you're happy to find that the first tuple is unchanged. After that, the problem is that you have no way to mach the remaining rows. Does B-B matches B-C or C-B or C-C was update or B-B and C-C have been deleted and the other are new rows?

You MUST rely on a key of any kind. Assuming you do it, the rest is conventional boring SQL.

ildanny
  • 371
  • 2
  • 10