Get date of last successful job run?

前端 未结 5 2206
日久生厌
日久生厌 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:07

    To get Last successfully run jobs:

    SELECT 
        h.[job_id]
        ,j.Name JobName
        ,CONVERT(CHAR(10), CAST(STR(run_date,8, 0) AS dateTIME), 111)   [LastRunDate]
       ,STUFF(STUFF(RIGHT('000000' + 
        CAST (run_time AS`` VARCHAR(6 ) ) ,6),5,0,':'),3,0,':') [LastRunTime]
       ,CASE run_status 
        WHEN 0 THEN 'Failed' 
        WHEN 1 THEN 'Succeeded' 
        WHEN 2 THEN 'Retry' 
        WHEN 3 THEN 'Cancelled' 
        WHEN 4 THEN 'In Progress' 
        END AS ExecutionStatus                                                 
        FROM [msdb].[dbo].[sysjobhistory] h 
        JOIN msdb.dbo.sysjobs j ON h.job_id=j.job_id 
        WHERE run_status=1 
        ORDER BY run_date DESC,run_time DESC
    

提交回复
热议问题