How to make a stored procedure (or other sql code) run multiple times at exactly the same time

The best way I have found to do this, is to use the WAITFOR TIME SQL command.

Here is an example. You are testing stored procedure sp_runsomething to ensure that the code is not going to cause any issues if run more than once at the same time. You could create two sql jobs and set them to execute at exactly the same time, however there is an easier way to do it from right within SSMS.

Sample code. Paste into as many windows as you like with the time you want them to execute.

WAITFOR TIME '09:21';   
EXEC sp_runsomething

The code will wait until the time as specified and then execute.

Let us know if this helps you – or you have other ideas you want to share on this topic.

Rob StGeorge
Senior SQL Server Database Administrator residing in Auckland, NZ

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.