Skip to content
Advertisement

How to query SQL Server Agent – all jobs’s error message result set

Question: how to query SQL Server Agent – all jobs’ error message result set

image-20200814085131688

Input:

select *
from [jobs's error masseage table]
where status = 'error' and date between '2020-05-01' and '2020-06-01'

Expected result:

jobname , runtime , status , message
xxx1 , 2020-05-03 , error , #)*)_(#_@$#
xxx2 , 2020-05-05 , error , #)*)_(#_@$#
....

What I’ve tried & know: I know Job Activity Monitor GUI form can do it, but it only contains last run as shown in this screenshot:

image-20200814085609180

Advertisement

Answer

I searched msdn and found dbo.sysjobhistory (Transact-SQL) – SQL Server | Microsoft Docs can do it

SELECT sj.name,
        sh.*
FROM msdb.dbo.sysjobs sj
JOIN msdb.dbo.sysjobhistory sh ON sj.job_id = sh.job_id
where run_status = 0 and run_date between '20200806' and '20200811'
order by run_date

image-20200814100930197

but it looks like only cotaining few days data.

image-20200814100844574

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement