Skip to main content
Print

Failed SQL Agent jobs

To query the Performance Store database for failed agent jobs, use:

select *
from dbo.v_latest_agent_job_executions e with (nolock)
inner join dbo.v_agent_jobs_all a with (nolock) on a.server_name = e.server_name and a.job_name = e.job_name
inner join dbo.v_servers s with (nolock) on s.server_name = e.server_name
left join dbo.agent_job_whitelist w with (nolock) on w.server_name = e.server_name and (w.job_name is null or e.job_name like w.job_name) and (w.category_name is null or a.category_name like w.category_name)
where e.run_status = 'Failed'
and a.enabled = 1
and a.discovered = 1
and w.server_name is null

Failed agent jobs can also be seen on the Agent jobs dashboard.

The alert will be visible on the Latest stats dashboard.

To exclude specific servers from this alert, see how to use the dbo.team_alert_exclude table in Alerting.

Table of Contents