﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / How to stop a jobstep and go to the next in a scheduled job. / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 23:55:25 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: How to stop a jobstep and go to the next in a scheduled job.</title><link>http://www.sqlservercentral.com/Forums/Topic1404744-391-1.aspx</link><description>Hey No problem, it worked for me in my testing so best of luck with it!</description><pubDate>Thu, 10 Jan 2013 00:10:19 GMT</pubDate><dc:creator>MyDoggieJessie</dc:creator></item><item><title>RE: How to stop a jobstep and go to the next in a scheduled job.</title><link>http://www.sqlservercentral.com/Forums/Topic1404744-391-1.aspx</link><description>Hi MyDoggieJessie,Thanks for your reply.I will try this in the next few days.Martijn</description><pubDate>Thu, 10 Jan 2013 00:02:51 GMT</pubDate><dc:creator>Marbo</dc:creator></item><item><title>RE: How to stop a jobstep and go to the next in a scheduled job.</title><link>http://www.sqlservercentral.com/Forums/Topic1404744-391-1.aspx</link><description>This should work...Create a new job that has "checking" code in it that will monitor the running job.  From the first job step of your existing job (or via a scheduled job would work too), fire off this new "job checking job" that can monitor things.[code="sql"]DECLARE @Status tinyint, @Elapsed int, @Threshold int, @JobToCheck sysnameSET @JobToCheck = 'MyJobToCheck'SET @Threshold = 60 * 1 /* Represented in seconds *//* Assign varibles */SELECT TOP 1 @Status = ISNULL(last_executed_step_id, 0)	FROM msdb.dbo.sysjobactivity 	WHERE job_id = (SELECT job_id from msdb.dbo.sysjobs WHERE name = @JobToCheck)		AND (last_executed_step_id = 1 OR last_executed_step_id IS NULL) --&amp;gt;&amp;gt; This is NULL when first step of job is currently executing	ORDER BY run_requested_date DESCWHILE (@Status = 0)BEGIN/* Check job status, and elapsed time */	SELECT TOP 1 @Status = ISNULL(last_executed_step_id, 0), 		@Elapsed = DATEDIFF(second, start_execution_date, GETDATE())	FROM msdb.dbo.sysjobactivity 	WHERE job_id = (SELECT job_id from msdb.dbo.sysjobs WHERE name = @JobToCheck)	ORDER BY run_requested_date DESC	IF @Elapsed &amp;gt; @Threshold	BEGIN	/* Stop, then restart job for the step you want */		EXECUTE msdb.dbo.sp_stop_job @job_name = @JobToCheck		EXECUTE msdb.dbo.sp_start_job @JobToCheck, @step_name = 'Step you want to restart the job at'		BREAK;	END	ELSE	BEGIN	/* Check every minute or so */		WAITFOR DELAY '00:01:00'	END	END[/code]</description><pubDate>Wed, 09 Jan 2013 10:05:17 GMT</pubDate><dc:creator>MyDoggieJessie</dc:creator></item><item><title>How to stop a jobstep and go to the next in a scheduled job.</title><link>http://www.sqlservercentral.com/Forums/Topic1404744-391-1.aspx</link><description>Hi fellow SQL server users,I have a SQL server agent job with several job steps. This job is scheduled and runs almost every night.Sometimes there is one step that is taking to much time to execute. I know of the possibillity to set the properties for a step what to do after failure or success but in this case the step is still executing. And i want to stop it automatically after a specific period of time, and let the job continue with the next step.Is there somebody who can help me.Thanks in advance.Martijn</description><pubDate>Wed, 09 Jan 2013 06:41:31 GMT</pubDate><dc:creator>Marbo</dc:creator></item></channel></rss>