SQL SERVER 查询作业执行情况

SELECT
    [job].[job_id] AS '作业唯一标识符'
   ,[job].[name] AS '作业名称'
   ,[jstep].[step_uid] AS '作业步骤唯一标识符'
   ,[jstep].[step_id] AS '步骤编号'
   ,[jstep].[step_name] AS '步骤名称'
   ,CASE [jstep].[last_run_outcome]
      WHEN 0 THEN '失败'
      WHEN 1 THEN '成功'
      WHEN 2 THEN '重试'
      WHEN 3 THEN '取消'
      WHEN 5 THEN '未知'
    END AS '上次运行状态'
   ,STUFF(STUFF(RIGHT('000000'
                      + CAST([jstep].[last_run_duration] AS VARCHAR(6)), 6), 3,
                0, ':'), 6, 0, ':') AS [LastRunDuration (HH:MM:SS)]
   ,[jstep].[last_run_retries] AS '上次运行重复执行次数'
   ,CASE [jstep].[last_run_date]
      WHEN 0 THEN NULL
      ELSE CAST(CAST([jstep].[last_run_date] AS CHAR(8)) + ' '
           + STUFF(STUFF(RIGHT('000000'
                               + CAST([jstep].[last_run_time] AS VARCHAR(6)),
                               6), 3, 0, ':'), 6, 0, ':') AS DATETIME)
    END AS '上次运行时间'
FROM [msdb].[dbo].[sysjobsteps] AS [jstep]
INNER JOIN [msdb].[dbo].[sysjobs] AS [job]
        ON [jstep].[job_id] = [job].[job_id]
WHERE job.enabled = 1
ORDER BY [jstep].[last_run_outcome],[job].[name], [jstep].[step_id]

 

posted @ 2024-11-22 11:00  竹楼风雨声  阅读(1)  评论(0编辑  收藏  举报