info@techdevops.com
TechDevOps.com
Explore Tools
Experts in Microsoft SQL Server Operations, Performance, Migrations, Replication & Cloud



Get SQL Agent Job Last Run Status
by BF (Senior MSSQL Operations - Enterprise, Cloud, Strategy)
2019-07-14







Get SQL Agent Job Last Run Status:

Select
t2.Name as 'Job Name',
dateadd(second, (last_run_time/10000*3600) + (((last_run_time%10000-last_run_time%100)/100)*60) + (last_run_time%100), convert(datetime,cast(nullif(last_run_date,0) as nvarchar(10)))) as [Last_Run_Datetime],
Last_Run_Date,
Last_Run_Time,
last_run_duration as 'Last_Run_Duration_HH_MM_SS',
Last_Run_Outcome,
Last_Outcome_Message,
t2.Date_Created,
t2.Date_Modified
FROM msdb.dbo.sysjobservers t1
inner join msdb.dbo.sysjobs t2 on t1.job_id = t2.job_id
where
last_run_date > '20190711'
order by [Last_Run_Datetime] desc

/*
last_run_duration
Duration that the job was run, in hours, minutes, and seconds. Computed by using the formula: (hours*10000) + (minutes*100) + seconds.
*/