/***************************************************************************
* Title : How to find the list of all the failed SQL Jobs in
SQL Server
SQL Server
* Problem Description: There are instances where we may need
to quickly see
the list of failed SQL Jobs in SQL
Server
to quickly see
the list of failed SQL Jobs in SQL
Server
****************************************************************************/
SELECT H.SERVER AS [SERVER],
J.[NAME] AS [NAME],
H.MESSAGE
AS [MESSAGE],
AS [MESSAGE],
CONVERT(NVARCHAR(100),H.RUN_DATE) + CONVERT(NVARCHAR(100),H.RUN_TIME) AS LastRun
FROM
SYSJOBHISTORY H
SYSJOBHISTORY H
INNER JOIN
SYSJOBS J
SYSJOBS J
ON H.JOB_ID = J.JOB_ID
INNER JOIN (SELECT MAX(H.INSTANCE_ID) AS INSTANCE_ID
FROM SYSJOBHISTORY
H
H
GROUP BY (H.JOB_ID)) T
ON H.INSTANCE_ID = T.INSTANCE_ID
WHERE J.[ENABLED] = 1
AND H.RUN_STATUS
= 0