SQL - How to find currently running job steps through TSQL

user3138788 picture user3138788 · Feb 6, 2014 · Viewed 15.7k times · Source

I am writing a query to find currently running job in SQL (I know we can view it in Job Active Monitor, but I've a need to do in TSQL). Though I can query sysjobactivity table to find currently running job, it's nowhere telling what job step is running (because my job might have more than 1 step).

Query I used:

SELECT s.name AS [JOB_NAME],
       '' AS [STEP_ID], 
       '' AS STEP_NAME, 
       'Processing' AS STATUS, 
       sja.run_requested_date AS START_TIME, 
       null AS END_DATE,
       convert(varchar, (getdate() - sja.run_requested_date), 8) AS Duration 
  FROM sysjobactivity sja, sysjobs s
 WHERE sja.job_id = s.job_id
   AND sja.run_requested_date >  getdate() - 1
   AND sja.stop_execution_date IS NULL

Please help me finding the step ID & Step name in which the job is currently progressing.

Answer

Naveen Kumar picture Naveen Kumar · Feb 6, 2014

I think below script help to get SQL Jobs with current execution step, try this

msdb.dbo.sp_help_job @execution_status = 1