Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 How to Setup SQL Server Agent job in a Loop
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 09/25/2013 :  19:39:19  Show Profile  Reply with Quote
What is the best way to Setup SQL Server Agent job in a Loop. I want
SQL Server Agent job to continuously run when the flag in the table reads false. When the flag in the table turns to true then the job completes each task until complete and then stops. I only want the job to continuously run for only two hours. This job depends on another job to complete. I hope I explained my problem.


Almighty SQL Goddess

38200 Posts

Posted - 09/25/2013 :  19:47:02  Show Profile  Visit tkizer's Homepage  Reply with Quote
Use a WHILE loop inside the job step. Have it check the table before each pass through the loop. If you want it to end in two hours, then add logic to handle that by checking getdate() and comparing with the time it started. If this job depends on another job, then have that other job be the one to start it via sp_start_job. Don't add a job schedule to this job.

Tara Kizer
SQL Server MVP since 2007
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000