Are you saying that you are copying data from TableA into TableB in 2000 row batches? And that you want to ensure that the data is only inserted once into TableA?
If yes, you'll need to provide an example.
When posting questions on a forum, you should provide the Data Definition Language (DDL) of your tables, some sample data, and the expected results. If you're troubleshooting, you should also post the actual results you're getting, so we can compare the differences.
Issue : Not full data is getting inserted at times.
Assumption is due to same time read and write happening.
Tried way-
If the current time and last inserted time
ismore than 10 minutes, then do the reading from destination table.
In other words, SourceTable is inserted by an application button click. Destination table is inserted via scheduler from source in 5min interval.
Scheduler take data in batch, process and mark flag=1 at the end.
Scenario is if scheduler run at 4pm . It starts reading with flag=0 records. Same time if the end user did a button click, record will be inserted with flag =0.
So, there may be chance like reading the same record inserting and cause conflict.
You could use UPDATE with OUTPUT on the scheduler - that will lock the table for the update and output the selected rows into a table variable. You then select from the table variable for the data.