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
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.