Get date of last successful job run?

前端 未结 5 1389
萌比男神i
萌比男神i 2021-02-20 16:48

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条回答
  •  梦毁少年i
    2021-02-20 16:57

    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.

提交回复
热议问题