GRANT SELECT ON THIS4.dbo.PACS_APPLY to xdjh
use [THIS4]
GO
GRANT SELECT ON [dbo].[PACS_APPLY] TO [xdjh]
GO
SELECT
[job].[job_id] AS '作业唯一标示符'
,[job].[name] AS '作业名称'
, CASE WHEN [jobh].[run_date] IS NULL
OR [jobh].[run_time] IS NULL THEN NULL
ELSE CAST ( CAST ([jobh].[run_date] AS CHAR ( 8 )) + ' '
+ STUFF(STUFF( RIGHT ( '000000'
+ CAST ([jobh].[run_time] AS VARCHAR ( 6 )), 6 ),
3 , 0 , ':' ), 6 , 0 , ':' ) AS DATETIME)
END AS '最后执行时间'
, CASE [jobh].[run_status]
WHEN 0 THEN '失败'
WHEN 1 THEN '成功'
WHEN 2 THEN '重试'
WHEN 3 THEN '取消'
WHEN 4 THEN '正在运行'
END AS '最后执行状态'
,STUFF(STUFF( RIGHT ( '000000' + CAST ([jobh].[run_duration] AS VARCHAR ( 6 )), 6 ),
3 , 0 , ':' ), 6 , 0 , ':' ) AS '最后运行持续时间'
,[jobh].[message] AS '最后运行状态信息'
, CASE [jsch].[NextRunDate]
WHEN 0 THEN NULL
ELSE CAST ( CAST ([jsch].[NextRunDate] AS CHAR ( 8 )) + ' '
+ STUFF(STUFF( RIGHT ( '000000'
+ CAST ([jsch].[NextRunTime] AS VARCHAR ( 6 )),
6 ), 3 , 0 , ':' ), 6 , 0 , ':' ) AS DATETIME)
END AS '下次运行时间'
FROM [msdb].[dbo].[sysjobs] AS [job]
LEFT JOIN (
SELECT
[job_id]
, MIN ([next_run_date]) AS [NextRunDate]
, MIN ([next_run_time]) AS [NextRunTime]
FROM [msdb].[dbo].[sysjobschedules]
GROUP BY [job_id]
) AS [jsch]
ON [job].[job_id] = [jsch].[job_id]
LEFT JOIN (
SELECT
[job_id]
,[run_date]
,[run_time]
,[run_status]
,[run_duration]
,[message]
,ROW_NUMBER() OVER ( PARTITION BY [job_id] ORDER BY [run_date] DESC , [run_time] DESC ) AS RowNumber
FROM [msdb].[dbo].[sysjobhistory]
WHERE [step_id] = 0
) AS [jobh]
ON [job].[job_id] = [jobh].[job_id]
AND [jobh].[RowNumber] = 1
ORDER BY [job].[name]
文章评论