How can I determine the status of a job?

前端 未结 14 2321
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 02:36

I have a Stored procedure which schedules a job. This Job takes a lot of time to get completed (approx 30 to 40 min). I need to get to know the status of this Job. Below det

14条回答
  •  孤街浪徒
    2020-11-30 02:50

    I would like to point out that none of the T-SQL on this page will work precisely because none of them join to the syssessions table to get only the current session and therefore could include false positives.

    See this for reference: What does it mean to have jobs with a null stop date?

    You can also validate this by analyzing the sp_help_jobactivity procedure in msdb.

    I realize that this is an old message on SO, but I found this message only partially helpful because of the problem.

    SELECT
        job.name, 
        job.job_id, 
        job.originating_server, 
        activity.run_requested_date, 
        DATEDIFF( SECOND, activity.run_requested_date, GETDATE() ) as Elapsed
    FROM 
        msdb.dbo.sysjobs_view job
    JOIN
        msdb.dbo.sysjobactivity activity
    ON 
        job.job_id = activity.job_id
    JOIN
        msdb.dbo.syssessions sess
    ON
        sess.session_id = activity.session_id
    JOIN
    (
        SELECT
            MAX( agent_start_date ) AS max_agent_start_date
        FROM
            msdb.dbo.syssessions
    ) sess_max
    ON
        sess.agent_start_date = sess_max.max_agent_start_date
    WHERE 
        run_requested_date IS NOT NULL AND stop_execution_date IS NULL
    

提交回复
热议问题