SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

MSSQL Job Monitoring Simplified using Simple Query

By Shashi Kant Chauhan,

I have made a solution for SQL server job Monitoring without using temp tables. The solution is based on a query which use OPENROWSET and query the stored procedure output accoding to various conditions specially Current execution status of the jobs.

I am using this query for monitoring more then 500 SQL server's with a combination of (SQL Server 2000, 2005 and 2008). I am using SQL Server Management Studio 2008 (SSMS) and its new feature Multi-Server query for monitoring the Current Executing jobs on various servers.


There are 8 exectution status of any jobs which is described as

Execution Status Description
0 Not idle or suspended
1 Executing
2 Waiting For Thread
3 Between Retries
4 Idle
5 Suspended
6 WaitingForStepToFinish
7 PerformingCompletionActions


and there are 4 possible outcomes of the jobs which is as

Last run outcome Description
0 Failed
1 Succeeded
3 Canceled
5 Unknown


exec(' SELECT a.name Job_Name, case when enabled = 1 then ''Yes'' else ''NO'' end Enabled,
case when current_execution_status =0 then ''Not idle or suspended'' when current_execution_status = 1 then ''Executing''
when current_execution_status = 2 then ''Waiting For Thread'' when
current_execution_status = 3 then ''Between Retries''
when current_execution_status = 4 then ''Idle'' when current_execution_status = 5 then ''Suspended''
when current_execution_status = 6 then ''WaitingForStepToFinish'' when current_execution_status = 7 then ''PerformingCompletionActions'' end Execution_Status
,current_execution_step, current_retry_attempt, Case when last_run_outcome = 0 then ''Failed'' when last_run_outcome = 1 then ''Succeeded''
when last_run_outcome = 3 then ''Canceled'' when last_run_outcome = 5 then
''Unknown'' End last_run_outcome
, last_run_date FROM OPENROWSET(''SQLOLEDB'',
''DRIVER={SQL Server};SERVER='+@@servername +';Trusted_Connection=yes;'',
''SET NOCOUNT ON;SET FMTONLY OFF;exec msdb.dbo.sp_help_job'') AS a
where last_run_outcome = 3

{Note: You can change the resultset according to your need. i.e.Last_run_outcomecan be 0 ,1,3,5 As description is mentioned in the table above and will provide you desired result. }


If you run the above query in SSMS (SQL Server 2008 Management Studio) using Multi-Server query. You will get the output like that

Server Name Job_Name Enabled Execution_Status Current_Execution_step Current_retry_attempt last_run_outcome last_run_date
SQLTest Data Load Yes Idle 0(unknown) 0 Canceled 20081202
SQLDBPROD Import Data Yes Idle 0(unknown) 0 Canceled 20081201


I have attempted to simplify the monitoring of SQL jobs in multiserver environment where you can easily identify the status of the jobs and its previous outcomes before attempting next execution with the help of simple queries and without using any external utlity


Kind Regards
Shashi Kant Chauhan

Total article views: 843 | Views in the last 30 days: 1
Related Articles

Executing status on SQL Server Agent Jobs

Jobs with Executing Status but not process the Jobs on SQL Server 2005 Agent


Job Monitor outcome results doubt

Outcome results in Sheduled jobs


What SQL Statements Are Currently Executing?

This article describes a utility that allows you to identify what SQL statements are currently execu...


Find Currently Running Query – T-SQL

Following script retrieves the queries currently executing on the server.


check DB statistics status

check DB statistics status

sql jobs