Last active
March 11, 2018 20:01
-
-
Save sqlpadwan/493978802f05b4dec46808cde3de84c8 to your computer and use it in GitHub Desktop.
Getting the last 5 days job history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
name, | |
steps.step_name, | |
command, | |
steps.server, | |
database_name, | |
hist.run_date, | |
hist.run_time, | |
hist.run_duration, | |
hist.run_status, | |
hist.message, | |
hist.sql_severity | |
FROM msdb.dbo.sysjobs job | |
INNER JOIN msdb.dbo.sysjobsteps steps ON job.job_id = steps.job_id | |
INNER JOIN msdb.dbo.sysjobhistory hist ON hist.job_id = steps.job_id and hist.step_id = steps.step_id | |
WHERE job.enabled = 1 | |
and hist.run_date > CONVERT(char(8), DATEADD(day, -5, GETDATE()), 112) | |
and run_status = 0 | |
order by hist.run_date desc, hist.run_time | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment