以下脚本为获取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的执行情况的更多相关文章

  1. SQL SERVER 查询Job作业基本信息及执行情况

    查询作业基本信息和作业执行情况 SELECT [jop].[job_id] AS '作业唯一标识符' ,[jop].[ name ] AS '作业名称' ,[dp].[ name ] AS '作业创建 ...

  2. 【原创】SQL SERVER 查询Job作业基本信息及执行情况

    查询作业基本信息和作业执行情况 SELECT [jop].[job_id] AS '作业唯一标识符' ,[jop].[ name ] AS '作业名称' ,[dp].[ name ] AS '作业创建 ...

  3. 如何在获取celery中的任务执行情况

    开始以为在flower中获取,原来flower也是从celery中获取的. 如果直接用celery命令,一直会提示拒绝连接. 网上说了,用django命令就可以的. 于是试了下,OK了. 这样,至少可 ...

  4. 使用history命令查看作业的整体执行情况

    1)通过使用history命令,我们可以深入到一个Job的任务级层面查看执行最快的任务,以及执行最慢的任务,以及其他的有用信息.命令如下: hadoop job -history /output “/ ...

  5. SQL查询作业执行情况

    查询作业的执行情况sql: SELECT [JobName] = JOB.name, [Step] = HIST.step_id, [StepName] = HIST.step_name, [Mess ...

  6. sqlserver 创建对某个存储过程执行情况的跟踪

    有时候需要抓取执行存储过程时某个参数的值,有时候程序调用存储过程执行后结果不太对,不确定是程序的问题还是存储过程的问题,需要单独执行存储过程看结果 即可用下面的方法 --=============== ...

  7. SQLSERVER新建表的时候页面分配情况是怎样的?

    SQLSERVER新建表的时候页面分配情况是怎样的? 再次感谢sqlskill网站和转载sqlskill网站文章并翻译的人,因为您们的转载和翻译让小弟又学习到新的东西o(∩_∩)o 文章中用到的工具: ...

  8. MSSQL优化之——查看语句执行情况

    MSSQL优化之——查看语句执行情况 在写SQL语句时,必须知道语句的执行情况才能对此作出优化.了解SQL语句的执行情况是每个写程序的人必不可少缺的能力.下面是对查询语句执行情况的方法介绍. 一.设置 ...

  9. Android(java)学习笔记72:线程的状态转换图以及常见执行情况

    1. 线程的状态转换图以及常见执行情况: 2. 线程状态类型: (1)新建状态(New):新创建了一个线程对象.(2)就绪状态(Runnable):线程对象创建后,其他线程调用了该对象的start() ...

随机推荐

  1. maven下载与配置环境变量

    1.打开maven官网下载 http://maven.apache.org/download.cgi 下载 解压(这里博主放在D盘下) 2.配置环境变量 验证是否配置成功 3.本地仓库配置

  2. 数据结构实习 - problem M 判断平衡二叉树

    writer:pprp date: 20171103 题目描述 给定一棵二叉树的中序和层序输出,判断是否为平衡二叉树的.如果是,输出YES如果不是输出NO. 输入 树结点个数 中序遍历序列 层序遍历序 ...

  3. 随笔分类 - java高级特性

    转自:http://www.cnblogs.com/linjiqin/category/282013.html

  4. ThinkPHP开发笔记-模型

    1.模型定义.在ThinkPHP中,可以无需进行任何模型定义.只有在需要封装单独的业务逻辑的时候,模型类才是必须被定义的,因此ThinkPHP在模型上有很多的灵活和方便性,让你无需因为表太多而烦恼. ...

  5. RQNOJ 356 mty的格斗 dp

    PID356 / mty的格斗 题目描述 ’恩 ~~这个和这个也是朋友.把他们放在一起......哇!终于完成了’mty费了好大劲,终于找出了一支最为庞大的军队. fyc很高兴,立马出征与人fight ...

  6. git branch 新建,推送与删除

    在开发的许多时候我们都需要使用git提供的分支管理功能. 1.新建本地分支:git checkout -b test  新建一个名为:test 的本地分支. 2.提交本地分支:git push ori ...

  7. Android6.0------权限申请RxPermissions

    前面写了Android6.0权限介绍和权限单个,多个申请,用的是纯Java代码,本文主要说的是借助第三方库来实现权限申请. 借助第三方库 RxPermissions来申请6.0权限. RxPermis ...

  8. 2-1 RHEL6.5 环境搭建与部署

    第二部分:Linux常见服务管理 2-1 RHEL6.5 环境搭建与部署 第二部分主要讲解的是开源服务搭建 学习方法与注意事项: 1. 端正态度,开始学习 2. 认真完成作业和实验(并详细记录) 3. ...

  9. net.paoding.analysis.exception.PaodingAnalysisException: dic home should not be a file, but a directory!

    Caused by: net.paoding.analysis.exception.PaodingAnalysisException: dic home should not be a file, b ...

  10. python 连接操作 各类数据库

    转载自MySQL Loners 一,python 操作 MySQL:详情见:这里 #!/bin/env python # -*- encoding: utf-8 -*- #-------------- ...