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

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 How to Setup SQL Server Agent job in a Loop

Author  Topic 

manninb
Starting Member

1 Post

Posted - 2013-09-25 : 19:39:19
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.

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-09-25 : 19:47:02
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
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -