2012-02-27 3 views
2

저장 프로 시저에 사용할 쿼리를 작성하여 설정 한 모든 에이전트 작업 내의 개별 단계에 대한 작업 단계 기록을 가져 왔습니다. 디자인에 결함이 있다는 것을 알기 전까지는 모든 것이 잘 작동한다고 생각했습니다.거짓 긍정 : 작업 단계 내역

msdb.dbo.sysjobsteps의 'job_outcome'열을 사용하여 작업이 실패했는지, 성공했는지, 또는 실행되지 않은 일부 단계가 '실패'로 되돌아 올 때까지 취소되었는지 확인하려고했습니다. 이제는 'last_run_duration'열을 봐야만한다는 것을 알았지 만 포함 시키려면 내 쿼리를 다시 작동시키는 방법을 모르겠습니다. 다른 접근법을 시도해야합니까? 아니면 다른 사람이 문제를 해결하기 위해 다음의 사례 진술을 어떻게 재 작업 할 수 있는지 제안 할 수 있습니까?

select convert(varchar(75), j.name) as [JobName] 
    , s.step_id 
    , convert(varchar(75), s.step_name) as [StepName] 
    , case s.last_run_outcome 
     when 1 then 'Success' 
     when 0 then 'Failed' 
     when 3 then 'Cancelled' end as [StepStatus] 
    , h.message 
    , max(s.last_run_date) as last_run_date 
    , max(s.last_run_time) as last_run_time 
    , MAX(s.last_run_duration) as last_run_duration 
    , max(ja.next_scheduled_run_date) as next_run 
    from msdb.dbo.sysjobs j 
inner join msdb.dbo.sysjobsteps s on j.job_id = s.job_id 
left join msdb.dbo.sysjobhistory h on s.job_id = h.job_id 
    and s.step_id = h.step_id 
    and s.last_run_date = h.run_date 
    and s.last_run_time = h.run_time 
left join msdb.dbo.sysjobactivity ja on s.job_id = ja.job_id 
    where j.enabled = 1 
    group by j.name, s.step_id, s.step_name, s.last_run_outcome, h.message 
    order by j.name, s.step_id 

답변

0

당신은 당신의 case 표현을 변경할 수 있습니다 먼저 last_run_date 확인 다른 case에 포함 할 :

, case when MAX(s.last_run_date) > 0 then 
     case s.last_run_outcome 
      when 1 then 'Success' 
      when 0 then 'Failed' 
      when 3 then 'Cancelled' end 
     else 'Never Ran' end as [StepStatus] 

당신은 last_run_duration을 확인 제안하지만, 작업이 매우 빠르게 실행될 경우이 제로가 될 수 있습니다 .. .

+0

고마워요! 그것은 내가 가지고 있었던 문제를 해결하는 것처럼 보였다. 나는 어떤 이유로 2 case 문을 사용하지 않을 생각입니다. – Upstart