Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
T-SQL
»
Dynamic TSQL to rerun failed jobs
Dynamic TSQL to rerun failed jobs
Rate Topic
Display Mode
Topic Options
Author
Message
asdsfssd
asdsfssd
Posted Tuesday, January 29, 2013 10:52 AM
Forum Newbie
Group: General Forum Members
Last Login: Wednesday, April 10, 2013 2:35 PM
Points: 5,
Visits: 26
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:
-- Declare some variables
DECLARE @count int
DECLARE @rancount int
DECLARE @job varchar(50)
-- Get failed jobs to a temp table rerunjb
select a.name from msdb..sysjobs a, msdb..sysjobhistory b
into #rerunjb
where a.job_id = b.job_id
and b.run_status = 0
and CONVERT(VARCHAR(8), b.run_date, 112) = CONVERT(VARCHAR(8),getdate(),112)
order by b.name
set @rancount = 0
set @count = (select count(*) from #rerunjb)
if @count > 0
while (@rancount < @count)
BEGIN
set @job = (select name from #rerunjb)
--comment out for now
--exec msdb..sp_start_job @job_name = '@job'
PRINT @job
set @rancount = @rancount+1
end
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.
Post #1413195
Luis Cazares
Luis Cazares
Posted Tuesday, January 29, 2013 11:33 AM
SSC Eights!
Group: General Forum Members
Last Login: Yesterday @ 7:51 PM
Points: 958,
Visits: 1,919
Do you get job1 printed twice? or only once?
Luis C.
Please don't trust me, test the solutions I give you before using them.
Forum Etiquette: How to post data/code on a forum to get the best help
Post #1413213
asdsfssd
asdsfssd
Posted Tuesday, January 29, 2013 12:01 PM
Forum Newbie
Group: General Forum Members
Last Login: Wednesday, April 10, 2013 2:35 PM
Points: 5,
Visits: 26
I'm getting twice Job 1. And I think the issue is
set @job = (select TOP 1 name from #rerunjb)
Post #1413225
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.