How to make query to wait for some time
WAITFOR clause will cause a delay in the execution of the subsequent statements until the condition is met.
WAITFOR clause can be used along with Time or Delay
WAITFOR DELAY
When WAITFOR DELAY is used a delay duration needs to be mentioned which is of the format HH:MM:SS format followed by one thousandth of a second’s value. In the following image the Delay value mentioned is 5 seconds, hence the execution of the next statement i.e GETDATE() is delayed for 5 seconds.
SELECT
GETDATE()
WAITFOR DELAY
'00:00:05:000'
SELECT
GETDATE()
WAITFOR TIME
When WAITFOR TIME is used, a time value needs to be mentioned which is of the format HH:MM:SS format followed by one thousandth of a second’s value. In the following image the time value mentioned is 09:11:05 AM, hence the execution of the next statement i.e GETDATE() is delayed till that time occurs. Remember that the Time value is a 24 hour format of time.
SELECT
GETDATE()
WAITFOR TIME
'09:11:05:000'
SELECT
GETDATE()
No comments:
Post a Comment