sqlserver获取代理服务作业job的执行情况
以下脚本为获取sqlserver的执行job
with testtemp as(
SELECT
sch.job_id,--his.[server] as InstanceName
CONVERT(nvarchar(150),his.[server]) as InstanceName
,--job.NAME as job_name
CONVERT(nvarchar(150),job.NAME) as job_name
,job.[enabled] as job_enabled
, --schs.[name] AS [ScheduleName]
CONVERT(nvarchar(150),schs.[name]) as ScheduleName
, CASE schs.[enabled]
WHEN 1 THEN 'Yes'
WHEN 0 THEN 'No'
else 'unknow'
END AS [IsEnabled]
, CASE
WHEN [freq_type] = 64 THEN 'Start automatically when SQL Server Agent starts'
WHEN [freq_type] = 128 THEN 'Start whenever the CPUs become idle'
WHEN [freq_type] IN (4,8,16,32) THEN 'Recurring'
WHEN [freq_type] = 1 THEN 'One Time'
else 'unkown'
END [ScheduleType]
, CASE [freq_type]
WHEN 1 THEN 'One Time'
WHEN 4 THEN 'Daily'
WHEN 8 THEN 'Weekly'
WHEN 16 THEN 'Monthly'
WHEN 32 THEN 'Monthly - Relative to Frequency Interval'
WHEN 64 THEN 'Start automatically when SQL Server Agent starts'
WHEN 128 THEN 'Start whenever the CPUs become idle'
else 'unkown'
END [Occurrence]
, CASE [freq_type]
WHEN 4 THEN 'Occurs every ' + CAST([freq_interval] AS VARCHAR(3)) + ' day(s)'
WHEN 8 THEN 'Occurs every ' + CAST([freq_recurrence_factor] AS VARCHAR(3))
+ ' week(s) on '
+ CASE WHEN [freq_interval] & 1 = 1 THEN 'Sunday' ELSE '' END
+ CASE WHEN [freq_interval] & 2 = 2 THEN ', Monday' ELSE '' END
+ CASE WHEN [freq_interval] & 4 = 4 THEN ', Tuesday' ELSE '' END
+ CASE WHEN [freq_interval] & 8 = 8 THEN ', Wednesday' ELSE '' END
+ CASE WHEN [freq_interval] & 16 = 16 THEN ', Thursday' ELSE '' END
+ CASE WHEN [freq_interval] & 32 = 32 THEN ', Friday' ELSE '' END
+ CASE WHEN [freq_interval] & 64 = 64 THEN ', Saturday' ELSE '' END
WHEN 16 THEN 'Occurs on Day ' + CAST([freq_interval] AS VARCHAR(3))
+ ' of every '
+ CAST([freq_recurrence_factor] AS VARCHAR(3)) + ' month(s)'
WHEN 32 THEN 'Occurs on '
+ CASE [freq_relative_interval]
WHEN 1 THEN 'First'
WHEN 2 THEN 'Second'
WHEN 4 THEN 'Third'
WHEN 8 THEN 'Fourth'
WHEN 16 THEN 'Last'
END
+ ' '
+ CASE [freq_interval]
WHEN 1 THEN 'Sunday'
WHEN 2 THEN 'Monday'
WHEN 3 THEN 'Tuesday'
WHEN 4 THEN 'Wednesday'
WHEN 5 THEN 'Thursday'
WHEN 6 THEN 'Friday'
WHEN 7 THEN 'Saturday'
WHEN 8 THEN 'Day'
WHEN 9 THEN 'Weekday'
WHEN 10 THEN 'Weekend day'
END
+ ' of every ' + CAST([freq_recurrence_factor] AS VARCHAR(3))
+ ' month(s)'
else 'unknown'
END AS [Recurrence]
, CASE [freq_subday_type]
WHEN 1 THEN 'Occurs once at '
+ STUFF(
STUFF(RIGHT('000000' + CAST([active_start_time] AS VARCHAR(6)), 6)
, 3, 0, ':')
, 6, 0, ':')
WHEN 2 THEN 'Occurs every '
+ CAST([freq_subday_interval] AS VARCHAR(3)) + ' Second(s) between '
+ STUFF(
STUFF(RIGHT('000000' + CAST([active_start_time] AS VARCHAR(6)), 6)
, 3, 0, ':')
, 6, 0, ':')
+ ' & '
+ STUFF(
STUFF(RIGHT('000000' + CAST([active_end_time] AS VARCHAR(6)), 6)
, 3, 0, ':')
, 6, 0, ':')
WHEN 4 THEN 'Occurs every '
+ CAST([freq_subday_interval] AS VARCHAR(3)) + ' Minute(s) between '
+ STUFF(
STUFF(RIGHT('000000' + CAST([active_start_time] AS VARCHAR(6)), 6)
, 3, 0, ':')
, 6, 0, ':')
+ ' & '
+ STUFF(
STUFF(RIGHT('000000' + CAST([active_end_time] AS VARCHAR(6)), 6)
, 3, 0, ':')
, 6, 0, ':')
WHEN 8 THEN 'Occurs every '
+ CAST([freq_subday_interval] AS VARCHAR(3)) + ' Hour(s) between '
+ STUFF(
STUFF(RIGHT('000000' + CAST([active_start_time] AS VARCHAR(6)), 6)
, 3, 0, ':')
, 6, 0, ':')
+ ' & '
+ STUFF(
STUFF(RIGHT('000000' + CAST([active_end_time] AS VARCHAR(6)), 6)
, 3, 0, ':')
, 6, 0, ':')
else 'unkown'
END [Frequency]
,job.category_id
,job.[description] as job_description
,his.sql_message_id
,his.sql_severity
,his.[message] as job_message
,his.run_status as last_run_status
,job.date_created
,'LastRunDateTime' =
CASE
WHEN his.run_date = 0 THEN null
ELSE msdb.dbo.agent_datetime(his.run_date, his.run_time)
END
,'NextRunDateTime' =
CASE
WHEN sch.next_run_date = 0 THEN null
ELSE msdb.dbo.agent_datetime(sch.next_run_date, sch.next_run_time)
END
,dateadd(second,(run_duration / 10000 * 3600 + (run_duration / 100) % 100 * 60 + run_duration % 100),msdb.dbo.agent_datetime(his.run_date, his.run_time)) as LastRunFinishDateTime
,((run_duration / 10000 * 3600 + (run_duration / 100) % 100 * 60 + run_duration % 100)) AS 'RunDurationSeconds'
FROM msdb..sysjobschedules AS sch
INNER JOIN msdb..sysjobs AS job ON sch.job_id = job.job_id
inner join msdb..sysschedules as schs on sch.schedule_id=schs.schedule_id
LEFT JOIN (select hi.* from msdb..sysjobhistory as hi inner join
(select job_id,max(instance_id) as instance_id
from msdb..sysjobhistory jh where jh.step_id = 0
GROUP BY jh.job_id) as jh on hi.job_id = jh.job_id and hi.instance_id = jh.instance_id) AS his ON his.job_id = job.job_id
)
select
isnull(job_id, null) as job_id,
isnull(InstanceName,'')as InstanceName,
isnull(job_name,'')as job_name,
isnull(job_enabled,0) as job_enabled,
isnull(ScheduleName,'')as ScheduleName,
isnull(IsEnabled,'')as IsEnabled,
isnull(ScheduleType, '')as ScheduleType,
isnull(Occurrence, '')as Occurrence,
isnull(Recurrence,'')as Recurrence,
isnull(Frequency,'')as Frequency,
isnull(category_id, 0)as category_id,
isnull(job_description , '')as job_description,
isnull(sql_message_id, 0)as sql_message_id,
isnull(sql_severity,0)as sql_severity,
isnull(job_message , '')as job_message,
isnull(last_run_status,0)as last_run_status,
isnull(date_created , '1900-01-01')as date_created,
isnull(LastRunDateTime,'1900-01-01')as LastRunDateTime,
isnull(NextRunDateTime,'1900-01-01')as NextRunDateTime,
isnull(LastRunFinishDateTime,'1900-01-01')as LastRunFinishDateTime,
isnull(RunDurationSeconds,0)as RunDurationSeconds
from testtemp where job_name<>'syspolicy_purge_history'
获取结果:
sqlserver获取代理服务作业job的执行情况的更多相关文章
- SQL SERVER 查询Job作业基本信息及执行情况
查询作业基本信息和作业执行情况 SELECT [jop].[job_id] AS '作业唯一标识符' ,[jop].[ name ] AS '作业名称' ,[dp].[ name ] AS '作业创建 ...
- 【原创】SQL SERVER 查询Job作业基本信息及执行情况
查询作业基本信息和作业执行情况 SELECT [jop].[job_id] AS '作业唯一标识符' ,[jop].[ name ] AS '作业名称' ,[dp].[ name ] AS '作业创建 ...
- 如何在获取celery中的任务执行情况
开始以为在flower中获取,原来flower也是从celery中获取的. 如果直接用celery命令,一直会提示拒绝连接. 网上说了,用django命令就可以的. 于是试了下,OK了. 这样,至少可 ...
- 使用history命令查看作业的整体执行情况
1)通过使用history命令,我们可以深入到一个Job的任务级层面查看执行最快的任务,以及执行最慢的任务,以及其他的有用信息.命令如下: hadoop job -history /output “/ ...
- SQL查询作业执行情况
查询作业的执行情况sql: SELECT [JobName] = JOB.name, [Step] = HIST.step_id, [StepName] = HIST.step_name, [Mess ...
- sqlserver 创建对某个存储过程执行情况的跟踪
有时候需要抓取执行存储过程时某个参数的值,有时候程序调用存储过程执行后结果不太对,不确定是程序的问题还是存储过程的问题,需要单独执行存储过程看结果 即可用下面的方法 --=============== ...
- SQLSERVER新建表的时候页面分配情况是怎样的?
SQLSERVER新建表的时候页面分配情况是怎样的? 再次感谢sqlskill网站和转载sqlskill网站文章并翻译的人,因为您们的转载和翻译让小弟又学习到新的东西o(∩_∩)o 文章中用到的工具: ...
- MSSQL优化之——查看语句执行情况
MSSQL优化之——查看语句执行情况 在写SQL语句时,必须知道语句的执行情况才能对此作出优化.了解SQL语句的执行情况是每个写程序的人必不可少缺的能力.下面是对查询语句执行情况的方法介绍. 一.设置 ...
- Android(java)学习笔记72:线程的状态转换图以及常见执行情况
1. 线程的状态转换图以及常见执行情况: 2. 线程状态类型: (1)新建状态(New):新创建了一个线程对象.(2)就绪状态(Runnable):线程对象创建后,其他线程调用了该对象的start() ...
随机推荐
- Feign PathVariable annotation was empty on param 0.
使用Feign的时候,如果参数中带有 @PathVariable形式的参数,则要用value=""标明对应的参数,否则会抛出IllegalStateException异常 如 @P ...
- 从0开始 数据结构 AC自动机 模板(from kkke)
AC自动机模板 2.4.1 头文件&宏&全局变量 #include <queue> #define MAXN 666666 #define MAXK 26//字符数量 st ...
- 如何将JS里变量的值赋给文本框
举个栗子: <html><HEAD><script type="text/javascript" language="Javascript1 ...
- LA 3971 组装电脑(二分)
https://vjudge.net/problem/UVALive-3971 题意:你有b块钱,想要组装一台电脑.给出n个配件各自的种类.品质因子和价格,要求每种类型的配件各买一个,总价格不超过b, ...
- R中的sub替换函数【转】
R中的grep.grepl.sub.gsub.regexpr.gregexpr等函数都使用正则表达式的规则进行匹配.默认是egrep的规则,也可以选用Perl语言的规则.在这里,我们以R中的sub函数 ...
- 创建node.js,blog
terminal npm init //创建项目 npm install --save express //安装 express 模块 npm install --save body-parser / ...
- 什么是JSON?
JSON是一种取代XML的数据结构,和xml相比,它更小巧但描述能力却不差,由于它的小巧所以网络传输数据将减少更多流量从而加快速度. JSON就是一串字符串 只不过元素会使用特定的符号标注. {} 双 ...
- Bootstrap 与 IE 兼容模式 关系讲解
IE 兼容模式 Bootstrap 不支持 IE 古老的兼容模式.为了让 IE 浏览器运行最新的渲染模式下,建议将此 <meta> 标签加入到你的页面中:Copy <meta htt ...
- Weex了解
weex描述 weex是一个使用web开发体验来开发高性能原生应用的框架,能支持vue.js框架.它可以实现用同一套代码来构建Andriod.IOS和web应用.可以实现使用JavaScript和流行 ...
- 手动建立Mysql表实体类技巧
首先执行一条sql语句,也可以在开发中插入数据.修改数据或者查询数据的某个属性时使用. select sc.COLUMN_NAME from information_schema.COLUMNS as ...