Hi guys,
The following SWQL query shows the Failed SQL Jobs.
1) I would like to show the user also the error message. In which column can I find it?
2) Also, the user would like to see only the jobs that have failed twice in a row (doesn't matter how much time between them). Any ideas?
SELECT
i.Name
,i.DetailsURL AS [_LinkFor_Name]
,'<a href="' + i.DetailsURL + '" target="_blank">' + i.sqlApplication.FullyQualifiedName + '</a>' as Application
,'/Orion/APM/SqlBlackBox/Images/StatusIcons/application_small_' + CASE WHEN i.sqlApplication.StatusDescription = 'Critical' THEN 'up-' ELSE '' END + ToLower(i.sqlApplication.StatusDescription) + '.png' AS [_IconFor_Application]
,i.sqlApplication.InstanceName
,i.JobInfoID
,i.ApplicationID
,i.sqlJobInfoAlert.Nodeid
,ToLocal(i.LastRunDate) AS [Last Run]
,CASE WHEN (i.LastRunDuration / 60) > 0 THEN (ToString((i.LastRunDuration / 60)) + 'm ' + ToString((i.LastRunDuration -(i.LastRunDuration / 60) * 60)) + 's') ELSE (ToString((i.LastRunDuration -(i.LastRunDuration / 60) * 60)) + 's') END AS [Duration]
,CASE WHEN i.LastRunStatus = 0 THEN 'Failed' WHEN i.LastRunStatus = 1 THEN 'Succeeded' WHEN i.LastRunStatus = 2 THEN 'Retry' WHEN i.LastRunStatus = 3 THEN 'Cancelled' WHEN i.LastRunStatus = 4 THEN 'In Progress' END AS [Outcome] ,'/Orion/APM/SqlBlackBox/Images/StatusIcons/job_' + CASE WHEN i.LastRunStatus = 0 THEN 'failed' WHEN i.LastRunStatus = 1 THEN 'succeeded' WHEN i.LastRunStatus = 2 THEN 'retry' WHEN i.LastRunStatus = 3 THEN 'cancelled' WHEN i.LastRunStatus = 4 THEN 'inprogress' END + '.png' AS [_IconFor_Outcome] FROM Orion.APM.SqlJobInfo i
WHERE i.LastRunStatus <> 1
ORDER BY i.LastRunStatus,i.LastRunDate desc