How to load updated data from source DB when source tables don't contain any updated date field for comparison in SSIS?

hamb 26 Reputation points
2022-05-27T15:55:01.513+00:00

Hi,

I am loading data from PROD DB (can't add any field in PROD) and the tables don't have any field which could compare with current date to load the updated records on daily basis in SSIS.

I have added a derived column "Date_Loaded" (with GETDate) and add a date_loaded column in the target database tables and loaded all the data from the sources but now I am stuck, how to load the updated PROD data for the next day.

Thanks.

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,702 questions
Developer technologies Transact-SQL
SQL Server Other
{count} vote

3 answers

Sort by: Most helpful
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-05-27T19:26:05+00:00

    You say that you cannot add columns in Prod, but maybe you can enable Change Tracking or Change Data Capture to track which rows that have been updated.

    Else you need to compare column by column. This can be a bit laboursome when there are nullable columns involved. But here is a trick to find all changed rows:

    SELECT ...
    FROM  src
    FULL JOUN trg ON src.pk = trg.pk
    WHERE NOT EXISTS (SELECT src.* INTERSECT SELECT trg.*)
    

    This works because for the set operators INTERSECT and EXCEPT, NULL counts like any other value.

    This answer is not particularly detailed of the very simple reason we know very little about your system, so I have to be generic.

    0 comments No comments

  2. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-05-27T20:58:26.41+00:00

    Yes copying the same table's data to another DB and added a column Date_Loaded in staging target DB's table (GetDate()) and no other transformation required here.

    So yet an option would be Transactional Replication. Then you can add extra columns in the subscriber as you see fit.

    0 comments No comments

  3. ZoeHui-MSFT 41,491 Reputation points
    2022-05-30T02:34:58.247+00:00

    Hi @hamb ,

    Have you consider to use Lookup Transformation to compare the data between the two tables and insert the new value to your destination table?

    an-overview-of-the-lookup-transformation-in-ssis

    You may also refer to ssis-dataflow-copy-only-changed-and-new-records to see if it could give you some ideas.

    Regards,

    Zoe


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.