March 2, 2019 at 1:34 pm
Hi,
I've this script that runs every hour to get the failed job.
the problem with this script is when there is a job that runs lets says for 2 hour and it's failed in the end the script will not find this failed job.
what can i do to get the failed jobs per hour even if the job is run more then an hour and failed?
THX
SELECT j.[name] as job_name,
s.step_name,
h.run_date,
h.run_time,
h.message
FROM msdb.dbo.sysjobhistory h
INNER JOIN msdb.dbo.sysjobs j
ON h.job_id = j.job_id
INNER JOIN msdb.dbo.sysjobsteps s
ON j.job_id = s.job_id
--AND h.step_id = s.step_id
WHERE h.run_status in (0,2,3) -- Failure
AND msdb.dbo.agent_datetime (h.run_date,h.run_time) >= (SELECT DATEADD (MI, -60, GETDATE()))
order by msdb.dbo.agent_datetime (h.run_date,h.run_time) desc
March 4, 2019 at 6:01 am
It's pretty simple to find such overlapping ranges. Have a gander at the following link to learn how... just change the point of reference from months to hours.
http://www.sqlservercentral.com/articles/T-SQL/105968/
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply