• monilps (3/6/2013)


    2 tables involved here...

    Same database...

    One big gulp...

    OK, trying to move a large number of records in one big batch is probably why it looks like no records have been put into your destination from your source table. They won't be committed until the statement completes so the new records are only visible to the session doing the insert. This is a bit of a wild guess, but if you need to remove the records from the staging table and put them into the permanent table, something like this would do, I use a script like this for a system:

    WHILE EXISTS(SELECT TOP 1 NULL FROM [dbo].[pp_staging])

    BEGIN

    DELETE TOP (5000) pps

    OUTPUT DELETED.[e_id], DELETED.[p_id], DELETED.[pr_id], DELETED.[s_name], DELETED.[pro_id],

    DELETED.[timestamp], DELETED.[extra], DELETED.[checked], DELETED.[timestamp_ts], SYSDATETIMEOFFSET()

    INTO [dbo].[pp] ([e_id], [p_id], [pr_id], [s_name], [pro_id],

    [timestamp], [extra], [checked], [timestamp_ts], [arrival_timestamp])

    FROM [dbo].[pp_staging] pps

    END

    If you need to keep the records in the staging table, it gets a bit trickier, because then you need to somehow keep track of which rows in the staging table you've already done and haven't done.