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
ありがとう!それは私が持っていた問題を解決するように思えました。私は何らかの理由で2つのケースステートメントを使用することを決して考えなかった。 – Upstart