SQL Server task monitoring script

Source: Internet
Author: User
Webnesbay. comsql-server-jobs-monitoring-Timeout @ jobstatusTABLE (latency, Last_Run_Dateint, Last_Run_Timeint, Next_Run_Dateint, Next_Run_Timeint, timeout, Requested_To_Run

Http://webnesbay.com/sql-server-jobs-monitoring-script/ SQL Server BEGIN DECLARE @ jobstatusTABLE (Job_ID uniqueidentifier, Last_Run_Date int, Last_Run_Time int, Next_Run_Date int, Next_Run_Time int, interval int, Requested_To_Run

Http://webnesbay.com/sql-server-jobs-monitoring-script/ SQL Server
BEGIN DECLARE @jobstatusTABLE(Job_ID uniqueidentifier, Last_Run_Date int, Last_Run_Time int, Next_Run_Date int,    Next_Run_Time int,Next_Run_Schedule_ID int, Requested_To_Run int,    Request_Source int, Request_Source_ID varchar(100),Running int, Current_Step int, Current_Retry_Attempt int, State int)INSERT INTO @jobstatusEXEC MASTER.dbo.xp_sqlagent_enum_jobs 1,garbage                 BEGIN                SELECT DISTINCT CASE                   WHEN state=1 THEN 'Job is Executing'                   WHEN state=2 THEN 'Waiting for thread to complete'                   WHEN state=3 THEN 'Between retries'                   WHEN state=4 THEN 'Job is Idle'                   WHEN state=5 THEN 'Job is suspended'                   WHEN state=7 THEN 'Performing completion actions'                 END AS State,sj.name,                CASE WHEN ej.running=1 THEN st.step_id ELSE 0 END AS currentstepid,                CASE WHEN ej.running=1 THEN st.step_name ELSE 'not executing' END AS currentstepname,                st.command, ej.request_source_id                FROM @jobstatus ej join msdb..sysjobs sj ON sj.job_id=ej.job_id                JOIN msdb..sysjobsteps st ON st.job_id=ej.job_id AND (st.step_id=ej.current_step or ej.current_step=0)                WHERE ej.running+1>1                ENDEND

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.