Get date of last successful job run?

前端 未结 5 2240
日久生厌
日久生厌 2021-02-20 16:09

I have a single step job that executes a stored procedure. I would like get the date of the last successful job execution time so that I can just update a delta instead of the w

5条回答
  •  心在旅途
    2021-02-20 17:11

    Since sysjobhistory only maintains a certain number of records, I recomend using sysjobactivity, which keeps the last execution "history" of each job and session.

    SELECT TOP 1 start_execution_date
    FROM msdb.dbo.sysjobactivity
    WHERE run_requested_date IS NOT NULL
    AND job_id = @job_id
    ORDER BY session_id DESC;
    

    NOTE: If a Job has not been executed during the life of a session, almost all values will be null.

    ALSO there is a system Stored Procedure sp_help_job that returns this information. It accepts job_id, enabled, etc. as parameters to return 1 or more records.

提交回复
热议问题