SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
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
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

manninb
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.

Thanks

tkizer
Almighty SQL Goddess

USA
35953 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
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.08 seconds. Powered By: Snitz Forums 2000