Created
April 6, 2022 09:43
-
-
Save codykonior/d2f40c758e65b1972bd4d8ca0154c2eb to your computer and use it in GitHub Desktop.
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 DISTINCT | |
CASE | |
WHEN ss.EngineEdition = 8 | |
THEN NULL | |
ELSE d.HostName | |
END | |
AS ComputerName, | |
CASE | |
WHEN ss.EngineEdition = 8 | |
THEN UPPER(esc.ObjectName) | |
WHEN ss.EngineEdition IS NOT NULL | |
THEN UPPER(d.HostName + COALESCE('\' + esc.InstanceName, '')) | |
END | |
AS ServerInstance, | |
td.TaskName, | |
thi.Message, | |
ts.LastSuccessTimeUtc, | |
ts.LastUpdatedTimeUtc, | |
thi.FaultText | |
FROM Tasks.TaskStatus ts | |
JOIN Tasks.TaskDefinition td | |
ON ts.TaskId = td.TaskId | |
JOIN Tasks.TaskHistoryItem thi | |
ON ts.TaskId = thi.TaskId | |
AND ts.OwnerId = thi.OwnerId | |
JOIN dbo.EventSource es | |
ON ts.OwnerId = es.ObjectID -- If it matches here it's Windows | |
OR ts.OwnerId = es.EventSourceConnectionId -- If it matches here it's SQL | |
JOIN dbo.EventSourceConnection esc | |
ON es.EventSourceConnectionId = esc.ObjectId | |
LEFT JOIN dbo.SqlServer ss | |
ON ts.OwnerId <> es.ObjectId -- Only join if the task is for SQL | |
AND esc.ObjectId = ss.ObjectId | |
JOIN dbo.Device d | |
ON d.Id = esc.DeviceId | |
WHERE thi.FaultText IS NOT NULL | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment