/* Hank Freeman */
use master
go
SELECT
ja.job_id,
j.name AS job_name,
ja.start_execution_date,
--2019-06-10 18:54:31.000
getdate() as 'NOW',
'0'+Cast(Datepart(hh,(getdate() - ja.start_execution_date)) as char(2)) + ':' +
Cast(Datepart(n,(getdate() - ja.start_execution_date)) as char(2)) + ':' +
'0'+Cast(Datepart(ss,(getdate() - ja.start_execution_date)) as char(2)) as 'Duration',
Cast(DATEDIFF(n,ja.start_execution_date,getdate()) as char(5)) as 'Duration_Mins',
ISNULL(last_executed_step_id,0)+1 AS cur_exec_step_id,
Js.step_name
FROM msdb.dbo.sysjobactivity ja
LEFT JOIN msdb.dbo.sysjobhistory jh
ON ja.job_history_id = jh.instance_id
JOIN msdb.dbo.sysjobs j
ON ja.job_id = j.job_id
JOIN msdb.dbo.sysjobsteps js
ON ja.job_id = js.job_id
AND ISNULL(ja.last_executed_step_id,0)+1 = js.step_id
WHERE ja.session_id = (
SELECT TOP 1 session_id
FROM msdb.dbo.syssessions
ORDER BY session_id DESC
)
AND start_execution_date is not null
AND stop_execution_date is null
order by 2
;