Created
July 9, 2015 14:53
-
-
Save MAOliver/b109d5f5b1d7d95449bf to your computer and use it in GitHub Desktop.
List currently running jobs - from here: http://sqlstudies.com/2013/09/05/a-t-sql-query-to-get-current-job-activity/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
ja.job_id, | |
j.name AS job_name, | |
ja.start_execution_date, | |
ISNULL(last_executed_step_id,0)+1 AS current_executed_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 agent_start_date DESC) | |
AND start_execution_date is not null | |
AND stop_execution_date is null; | |
--EXEC msdb.dbo.sp_stop_job N'JobName' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment