﻿<?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 7,2000 / T-SQL  / Dynamic TSQL to rerun failed jobs / 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 21:23:08 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Dynamic TSQL to rerun failed jobs</title><link>http://www.sqlservercentral.com/Forums/Topic1413195-8-1.aspx</link><description>I'm getting twice Job 1. And I think the issue is [quote]set @job = (select TOP 1 name from #rerunjb)[/quote]</description><pubDate>Tue, 29 Jan 2013 12:01:11 GMT</pubDate><dc:creator>asdsfssd</dc:creator></item><item><title>RE: Dynamic TSQL to rerun failed jobs</title><link>http://www.sqlservercentral.com/Forums/Topic1413195-8-1.aspx</link><description>Do you get job1 printed twice? or only once?</description><pubDate>Tue, 29 Jan 2013 11:33:13 GMT</pubDate><dc:creator>Luis Cazares</dc:creator></item><item><title>Dynamic TSQL to rerun failed jobs</title><link>http://www.sqlservercentral.com/Forums/Topic1413195-8-1.aspx</link><description>Need help in scripting - I'm trying to create a script to run on SQL Servers with the following goals in mind.1) It'll look for failed jobs.2) Re-run those failed jobs.The script I have:[quote]-- Declare some variablesDECLARE @count intDECLARE @rancount intDECLARE @job varchar(50)-- Get failed jobs to a temp table rerunjbselect a.name from msdb..sysjobs a, msdb..sysjobhistory binto #rerunjbwhere a.job_id = b.job_idand b.run_status = 0and CONVERT(VARCHAR(8), b.run_date, 112) = CONVERT(VARCHAR(8),getdate(),112)order by b.nameset @rancount = 0set @count = (select count(*) from #rerunjb)if @count &amp;gt; 0while (@rancount &amp;lt; @count)  BEGINset @job = (select name from #rerunjb)--comment out for now --exec msdb..sp_start_job @job_name = '@job'PRINT @jobset @rancount = @rancount+1end[/quote]I'm getting 2 row(s) affected (which is right - 2 rows are inserted into #rerunjb); but I only get Job1 (from the PRINT @job). For some reason it's not looping.</description><pubDate>Tue, 29 Jan 2013 10:52:07 GMT</pubDate><dc:creator>asdsfssd</dc:creator></item></channel></rss>