|
|
Question : How to check if a sql job is running for a long time
|
|
how to check if one of the sql job is running for long time. i have seen some of my jobs when they fails they just keep running for the long time. I would like to find our if the job is running for a long time (6 hours) then just stop the job and run it again.
|
Answer : How to check if a sql job is running for a long time
|
|
sry - missed a bit
select datediff(m,getdate(), min(h.run_date)) as minutes_running from msdb..sysjobs j, msdb..sysjobhistory h where j.name = 'your job name' and j.job_id = h.job_id and exists (select 1 from msdb..sysjobhistory h2 where h2.job_id = h.job_id and h2.run_status = 4)
|
|
|
|