I am trying to copy records from a table (table A) from one system (SQL Server) to a table (table B) in another system (Oracle). Table B does not allow duplicates, has 20 fields, with two indices (one with 8 fields in the index and the other with 9 fields in the index; 8 of the fields in both indices are the same). One of the fields is named SequenceNumber which is included in both indices.
For Table A I use a query that uses the RowNumber function to increment the SequenceNumber field if there are duplicates. For Table B I have a query that provides only the fields in the smaller index (8 fields) which I group together and use the MAX function on the SequenceNumber field so I will only have the records which have the greatest SequenceNumber for that index. Both tables are sorted by the index fields.
In my SSIS package
- I first create a temp table which matches the Oracle table using an Execute SQL task.
- Then I have a Data Flow task where i use a Merge Join transform to left outer join Table A with Table B based on the smaller index (8 field). Then using a Conditional Split transform I separate New Records from Existing Records. I am checking whether SequenceNumber is null from Table B to tell which type of record it is (New or Existing). The New Records I connect to a Merge transform but the Existing Records I connect to a Derived Column transform to increment the SequenceNumber field depending on which SequenceNumber is greater from Table A or Table B. If Table B SequenceNumber is greater than Table A SequenceNumber I add them together and make that the new SequenceNumber. If not I add 1 to Table A SequenceNumber. Then I connect it to the Merge transform. This is inserted into the temp table.
- Then I connect this Data Flow task to another Data Flow Task where I copy the temp table records into Table B.
- I use another Data Flow task to update a Posted field in Table A to mark the record as posted.
- Finally I use an Execute SQL task to drop the temp table.
I am finding it is not increment the SequenceNumber so that it does not allow the records to be inserted.
Where am I going wrong in my logic?
Thanks for any help that can be provided.
Fred