• 1st - add an identity column to your staging table.

    You need a way to distinguish between different duplicate rows.

    2nd, use that staging ID in Error table instead of its own identity column.

    3rd, create set of insert statements - 1per each type of errors, inserting rows from staging to error.

    4th, insert all the records from staging which don't have their ids recorder in error into destination table.

    5th, clean up staging. Use delete, not truncate, as it would reset identity, and you don't wanna do it.

    _____________
    Code for TallyGenerator