Last active
March 10, 2023 18:56
-
-
Save Otterpohl/13c8bf5335520b7a7a561436e6d1ca09 to your computer and use it in GitHub Desktop.
Fetches the full failed text from an Agent Job
This file contains hidden or 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 CAST(RIGHT(JH.run_date, 2) AS CHAR(2)) + '/' + CAST(SUBSTRING(CAST(JH.run_date AS CHAR(8)), 5, 2) AS CHAR(2)) + '/' + CAST(LEFT(JH.run_date, 4) AS CHAR(4)) AS date_run | |
,LEFT(RIGHT('0' + CAST(JH.run_time AS VARCHAR(6)), 6), 2) + ':' + SUBSTRING(RIGHT('0' + CAST(JH.run_time AS VARCHAR(6)), 6), 3, 2) + ':' | |
+ LEFT(RIGHT('0' + CAST(JH.run_time AS VARCHAR(6)), 6), 2) AS time_run | |
,JS.step_name | |
,JH.run_duration | |
,CASE | |
WHEN JSL.log IS NULL THEN JH.message | |
ELSE JSL.log | |
END AS log_output | |
FROM msdb.dbo.sysjobsteps AS JS | |
INNER JOIN msdb.dbo.sysjobhistory AS JH | |
ON JS.job_id = JH.job_id | |
AND JS.step_id = JH.step_id | |
LEFT OUTER JOIN msdb.dbo.sysjobstepslogs AS JSL | |
ON JS.step_uid = JSL.step_uid | |
WHERE JS.step_id <> 0 | |
AND JH.run_status = 0 | |
ORDER BY JS.step_id ASC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment