You can add more value to the status field of the Sales table:
- Not processed
- Treatment
- Processed
Thus, you do not need to block lines (and pages in MS SQL Server) for the entire time required to send files via FTP. You simply lock the corresponding records when they are selected, then update the status to "Processing" and, finally, you release the lock.
After completing the FTP job, you will update the corresponding entries as "Processed".
You must also develop a planned process to check if the FTP job has failed or not. The status of entries related to failed FTP processes must be updated to Not Processed again.
Edit: you can find the SQL script below
begin tran declare @toBeProcessed table(saleid int); insert into @tobeProcessed select saleid from Sales (rowlock) where status = 'NotProcessed' update Sales set status = 'Processing' where saleid in (select saleid from @toBeProcessed) commit select * from @toBeProcessed
source share