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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Loop to run Sp_Start_Job

Author  Topic 

sirrahhc
Starting Member

2 Posts

Posted - 2010-04-07 : 09:58:50
Hey guys, how's it going?? I'll be honest, I'm terrible when it comes to loops...so with that said, here's what I would like to accomplish. I ran a query to get all of the reports that run at a certain time from the sys.jobs table and dropped those values into a temp table (tmpJobs). The field that denotes the jobs is called NAME. I would now like to loop through that table and run the sp_start_job for every NAME value in the tmpJobs table. The below code will run the sp_start_job for the one record from the sys.jobs table but I would instead like to loop through my tmpJobs table and run sp_start_job for all values in that table. Any suggestions?? Thanks in advance!!!!!


declare @x varbinary(1000)

select @x= job_id from
MSDB.dbo.sysjobs where name = '9AF35912-DDCB-4F09-B1E5-D68A93BF508C'
exec msdb..sp_start_job @job_id = @x

Chris Harris

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-07 : 10:11:26
Get an idea from method 2

http://beyondrelational.com/blogs/madhivanan/archive/2010/03/01/how-to-disable-all-jobs-using-a-query.aspx


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sirrahhc
Starting Member

2 Posts

Posted - 2010-04-09 : 09:16:29
Cool, thanks madhivanan!! This looks pretty close to what I want to do...

Chris Harris
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-09 : 09:39:35
quote:
Originally posted by sirrahhc

Cool, thanks madhivanan!! This looks pretty close to what I want to do...

Chris Harris


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -