Skip to main content

SQL Server Agent query to pull the currently running jobs and what step they are on.

select ja.job_id, as job_name,
    ISNULL(last_executed_step_id, 0) + 1 as current_executed_step_id,
from msdb.dbo.sysjobactivity as ja
left join msdb.dbo.sysjobhistory as jh
    on ja.job_history_id = jh.instance_id
join msdb.dbo.sysjobs as j
    on ja.job_id = j.job_id
join msdb.dbo.sysjobsteps as 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
                       from msdb.dbo.syssessions
                       order by
                           agent_start_date desc)
      and start_execution_date is not null
      and stop_execution_date is null;