So the problem goes like this:
I have a table with two columns namely source query and target query. each row contains a sql query for a informatica mapping from source side and target side and we needed to build a reconciliation procedure which take those two values for each row and generate there output and store it in temp table say temp1 and temp2 and then compare the result of these two temp tables. I Did this by creating two tables and then bulk fetching through two cursors and comparison was done using minus set operator for both the tables and then we got the different rows from there.
Now here comes the tricky part , what we have to do is check those rows which have different value and output the name of the column where there is a change and also output the source side values(temp1) and target side values(temp2).
If I had known the structure of the tables before then yes hard-coding was a way to get there but since the tables temp1
and temp2
are getting dynamically created therefore I'm not able to get my head around this situation, I mean how to get the column name and those two values using a procedure which dynamically loop through row and check where the value is changing and then output those two values and the column name.
Help me ! if you provide me a code for this , it will be really helpful.
Sample dataset
SOURCE
PK COLUMN1 COLUMN2 COLUMN3 COLUMN4
2 NAME2 VALUE2 3 4
1 NAME1 VALUE1 2 3
3 NAME3 VALUE3 4 5
TARGET
PK COLUMN1 COLUMN2 COLUMN3 COLUMN4
1 NAME1 VALUE1 2 3
2 NAME2 VALUE2 4 4
3 NAME3 VALUE3 4 5
now
SELECT * FROM SOURCE MINUS SELECT * FROM TARGET
gives
PK COLUMN1 COLUMN2 COLUMN3 COLUMN4
2 NAME2 VALUE2 3 4
and
SELECT * FROM TARGET MINUS SELECT * FROM SOURCE
gives
PK COLUMN1 COLUMN2 COLUMN3 COLUMN4
2 NAME2 VALUE2 4 4
we can see that column3
value got changed from 3 to 4.
So what we need is something like this
COLUMN_NAME OLD_VALUE NEW_VALUE
COLUMN3 3 4
Tables source and target are created from a procedure which take the sql for source and target table for another table that has two columns one is source query and other is target query and each row in this table has a different query for recon also the number of column and there name can change next time these table are created.