Sql-Server

如何獲得單個作業中每個單獨步驟的執行持續時間(以分鐘為單位)?

  • August 19, 2019

完整的Run_Duration工作sysjobhistory。有沒有辦法得到這個?[msdb].[dbo].[sysjobactivity]只有最後一步。

這應該讓你開始……

select 
   jobs.name
   ,jobs.description
   ,steps.step_id
   ,steps.step_name
   ,steps.last_run_outcome
   ,last_run_time = stuff(stuff(right('00000' + cast(steps.last_run_time as varchar),6),3,0,':'),6,0,':')
   ,last_run_duration = stuff(stuff(right('00000' + cast(steps.last_run_duration as varchar),6),3,0,':'),6,0,':')
from [msdb].[dbo].[sysjobs] jobs
inner join [msdb].[dbo].[sysjobsteps] steps on
steps.job_id = jobs.job_id
order by jobs.job_id, steps.step_id

在這種情況下,您使用

$$ sysjobsteps $$我將所有數據儲存在哪裡$$ sysjobHistory $$下面給出了以秒為單位的持續時間。我的建議: SELECT top 1000 j.name as JobName, step_id, jh.step_name StepName, CONVERT(CHAR(10), CAST(STR(jh.run_date,8, 0) AS dateTIME), 112) as RunDate, STUFF(STUFF(RIGHT('000000' + CAST ( jh.run_time AS VARCHAR(6 ) ) ,6),5,0,':'),3,0,':') RunTime, STUFF(STUFF(RIGHT('000000' + CAST ( jh.run_duration AS VARCHAR(6 ) ) ,6),5,0,':'),3,0,':') RunDuration, case jh.run_status when 0 then 'failed' when 1 then 'Succeded' when 2 then 'Retry' when 3 then 'Cancelled' when 4 then 'In Progress' end as ExecutionStatus, FROM sysjobhistory jh inner join sysjobs j ON j.job_id = jh.job_id ORDER BY j.name, jh.run_date, jh.run_time

引用自:https://dba.stackexchange.com/questions/207748