Support our 100% FREE Projects: Donate Now OR Sponsor Now


  

sql server wait for delay

SQL Server has an option to wait for delay which means that you can pause your SQL query code (batch) or pause stored procedure for a specified time (<24h) using delay option. There is also an option to specity time (WAITFOR TIME) which you can check in the link at the bottom.

Below is simple example how you can "pause" script using wait delay. In this case I have wait specified for 2 seconds

sql server wait for delay in sql and stored procedure simple example

 There are several scenarios where you would like to pause code in ther words delay execution. They usually relate to cases where you execute code and the codes moves on without waiting to finish it. I personally used this method to execute a SQL Server job multiple times with different parameters. So in my case I had to execute a job multiple times the problem I had when I ran a stored procedure to run a job it would go to next step without waiting to finish so I had to embed logic to check if the job finished running before I started the same job again with different parameter. This is where

 

WAITFOR DELAY Example

Below is example where I use wait delay and can be adjusted for your own needs.

In my example I use Condition which you can replace with your own real life condition that allows me to do a loop until condition changes to true/1. In the loop I wait 30 seconds and then check if minute of current time is 30 and if yes I change condition to true and exit the loop.

This code is not real life example but it should be easy to adjust it. Just by chaing conditon and adding extra line of code to perform an action

 

sql server wait for delay in sql and stored procedure real life example

 

 

 

Share: Share on FacebookShare on Google PlusTweet it
Comments Add Comment
No data was returned. Share your thoughts, questions and suggest improvements:
Add Comment

You found us! Below are 50 most popular searched keywords

created at TagCrowd.com

Disclaimer: While every caution has been taken to provide our readers with most accurate information and honest analysis, please use your discretion before taking any decisions based on the information in this blog. Author will not compensate you in any way whatsoever if you ever happen to suffer a loss/inconvenience/damage because of/while making use of information in this blog.