如何将此脚本修改为仅选择每个作业名称的最新执行?
z = s
答案 0 :(得分:0)
根据您的需要更改订单..
SELECT j.name JobName,h.step_name StepName,
CONVERT(CHAR(10), CAST(STR(h.run_date,8, 0) AS dateTIME), 111) RunDate,
STUFF(STUFF(RIGHT('000000' + CAST ( h.run_time AS VARCHAR(6 ) ) ,6),5,0,':'),3,0,':') RunTime,
h.run_duration StepDuration,
case h.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,
h.message MessageGenerated
sysjobs j
cross apply
(
select top 1 b.columns you need
from sys.jobhistory b where b.job_id=j.job_id
order by RunDate desc
) h