Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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: 750 | Views in the last 30 days: 5
 
Related Articles
FORUM

Executing status on SQL Server Agent Jobs

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

FORUM

Job Monitor outcome results doubt

Outcome results in Sheduled jobs

ARTICLE

What SQL Statements Are Currently Executing?

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

FORUM

check DB statistics status

check DB statistics status

SCRIPT

Check SQL Agent Job Status

Useful for when you have something depending on the outcome of a job.

Tags
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones