Question: how to query SQL Server Agent – all jobs’ error message result set
Input:
x
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:
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
but it looks like only cotaining few days data.