CREATE procedure usp_errorjob
AS
SET NOCOUNT ON;
select B.name,
CASE
WHEN A.[run_date] IS NULL OR A.[run_time] IS NULL THEN NULL
ELSE CAST(CAST(A.[run_date] AS CHAR(8)) + ' '
+ STUFF( STUFF(RIGHT('000000' + CAST(A.[run_time] AS VARCHAR(6)), 6)
, 3, 0, ':') , 6, 0, ':') AS DATETIME)
END AS [StartDateTime] ,
STUFF(
STUFF(RIGHT('000000' + CAST([A].[run_duration] AS VARCHAR(6)), 6)
, 3, 0, ':')
, 6, 0, ':')
AS [LastRunDuration (HH:MM:SS)],
CASE A.[run_status]
WHEN 0 THEN 'Failed'
WHEN 1 THEN 'Succeeded'
WHEN 2 THEN 'Retry'
WHEN 3 THEN 'Canceled'
WHEN 4 THEN 'Running' -- In Progress
END AS [RunStatus]
, A.message from
[msdb].[dbo].[sysjobhistory] AS A
inner join [msdb].[dbo].[sysjobs] B
ON A.job_id = B.job_id
where convert(datetime, cast(A.run_date as varchar(20)), 121) > getdate() -7--성공과 실행중인 JOB 제외
AND A.run_status NOT IN (1)
AND B.enabled =1 --사용중인 JOB
AND name not like '%ERRORLOG Cycling%' --원래 실패할 수 있기 때문에 이 작업은 뺀다.
order by [StartDateTime] DESC
'SQL SERVER' 카테고리의 다른 글
전체DB들의 LDF SIZE확인 (0) | 2023.09.11 |
---|---|
실행중인 SQL확인 (0) | 2023.09.11 |
synonym의 base object 조회 (0) | 2022.12.15 |
전체Table Size 확인 (0) | 2022.11.08 |
SQL 실행횟수 모니터링 (0) | 2022.03.15 |