• Two things to add.

    One is that if you built this import routine in a recursive fashision you could have something like:

    exec ImportRecords @StartRecord, @EndRecord, @BlockSize.

    The first level of recursion would just break the data into segments based on the block size and call back to the SP recursively in a loop. After the first level of recursion @EndRecord - @StartRecord <= @BlockSize. If that was the case the code would insert the data within a try catch block.

    Then if you made the Block size a power of 10 (1000 or 10000) each level of error handling within the recursion would have a loop that would break the errored block into 10 peices, set @BlockSize = @BlockSize / 10 and retry. If there was only one error in a block of 10000 records, this would recurse down in to a loop that processed 1000 records at a time. The 9 good blocks would have no errors and the 9000 good records would process in the third layer of recursion.

    Then block of 1000 of the remaining records in errored block would process in a fourth layer of recursion 100 records at time. This would continue until errors were caught and @BlockSize = 1. In that case you would just log the error rather than recurse down again.

    Of course you would also need some kind of check in the loop to make sure that the recursive value of @EndRecord never exceeded the passed in value of @EndRecord.

    The second point is that many error conditions could be found using set based operations to set and error status prior to attempting to insert the records.