在SQL Server Mgmt Studio中,可以查询“SQL Server代理>工作' [英] Within SQL Server Mgmt Studio, is it possible to query against 'SQL Server Agent > Jobs'

查看:132
本文介绍了在SQL Server Mgmt Studio中,可以查询“SQL Server代理>工作'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQL Server Mgmt Studio中,是否可以查询SQL Server代理>作业,并成功将为失败的作业在24小时内转换为类似于Excel?

Within SQL Server Mgmt Studio, is it possible to query against 'SQL Server Agent > Jobs' and successfully transfer the results produced for 'failed Jobs within a 24hr period' to something like Excel?

推荐答案

我通常创建一个报表,使用类似的查询下面的一个查找失败的所有作业和哪些步骤失败。你可以过滤它为你想要的工作。所有信息都在msdb数据库中。

I usually create a report that uses a similar query to the one below to find all the jobs that failed and what steps failed. You can filter it for the job you want as well. All the information is in the msdb database.

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
FROM sysjobhistory h inner join sysjobs j
ON j.job_id = h.job_id
where h.run_status = 0 and CONVERT(varchar(8),h.run_date,112) = CONVERT(varchar(8),GetDate(),112)

这篇关于在SQL Server Mgmt Studio中,可以查询“SQL Server代理>工作'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆