While loop for batch insert

I think the problem is that your @row_counter test is in the OUTER JOIN

AND A.RNO between @row_counter and (@row_counter + @batch_size)

so is only restricting the rows from ad_08142015,it will still select/insert every row from #DATA every loop iteration

Why are you using NOLOCK? Very dangerous in this type of situation.

1 Like