select j.name as JobName, s.step_id as Step, s.step_name as StepName,
msdb.dbo.agent_datetime(run_ date, run_time) as RunDateTime,
((run_duration/10000*3600 + (run_duration/100)%100*60 + run_duration%100 + 31 ) / 60) as RunDurationMinutes
From msdb.dbo.sysjobs j
INNER JOIN msdb.dbo.sysjobsteps s ON j.job_id = s.job_id
INNER JOIN msdb.dbo.sysjobhistory h ON s.job_id = h.job_id
WHERE j.[enabled] = 1 -- Only Enabled Jobs
AND j.name = 'YourJobName' -- specific job
AND h.run_status = 1 -- 0=Failed, 1=Succeeded, 2=Retry, 3=Cancelled, 4=In Progress
AND s.step_id = 3 -- specific step
ORDER BY j.name, msdb.dbo.agent_datetime(run_ date, run_time) desc
No comments:
Post a Comment