Suppose, We are working on a stored procedure in which some complex operation is going. We are fetching some value from a table and running some custom operations and after ending of this complex operation, we want a pause of suppose 10 seconds to run another job then in such situation we will use
“WAITFOR DELAY HH:MM: SS”
For example if we want to run select command (second statement) after 10 second delay of first command execution then we will use this as shown in below
INSERT INTO tblStudent (StudentId, StudentName)
VALUES (‘123’,’ABc’)
-- in the background we are running some cursor which would take aprox 10 seconds so we are waiting for 10 seconds here
WAITFOR DELAY 00:00:10
SELECT * FROM tblStudentHistory
In other situation suppose you want to run specific command after particular time then in such cases we will use “WAITFOR TIME HH: MM: SS”
suppose
“WAITFOR TIME 22:30:45 “ it means SQL statement will pause till 10:30:45 PM
I hope this tips may help you somewhere in your project.
Thanks
Enjoy!!!
RJ!!!