在SQL Server中判断一个作业是否正在运行
2012-08-15 11:31
381 查看
select step_id,run_status,run_date As rundate
--a.run_time, a.*
from msdb.dbo.sysjobhistory a
inner join msdb.dbo.sysjobs b on a.job_id=b.job_id
where b.name='PCDBI'
order by run_date DESC,step_id Asc
作业的执行状态run_status:
0 = 失败
1 = 成功
2 = 重试
3 = 取消
4 = 正在进行
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- author : p.c.w.l
-- source : www.sqlstudy.com
-- create : 2008-01-01
-- descr : a simple sql script to view sql server jobs run status
--------------------------------------------------------------------------------
select category = jc.name,
category_id = jc.category_id,
job_name = j.name,
job_enabled = j.enabled,
last_run_time = cast(js.last_run_date as varchar(10)) + '-' + cast(js.last_run_time as varchar(10)),
last_run_duration = js.last_run_duration,
last_run_status = js.last_run_outcome,
last_run_msg = js.last_outcome_message + cast(nullif(js.last_run_outcome,1) as varchar(2)),
job_created = j.date_created,
job_modified = j.date_modified
from msdb.dbo.sysjobs j
inner join msdb.dbo.sysjobservers js
on j.job_id = js.job_id
inner join msdb.dbo.syscategories jc
on j.category_id = jc.category_id
where j.enabled = 1
and js.last_run_outcome in (0,1,3,5) -- 0:Fail 1:Succ 3:Cancel 5:First run
and jc.category_id not between 10 and 20 -- repl
/*
category_id name
0 [Uncategorized (Local)]
1 Jobs from MSX
2 [Uncategorized (Multi-Server)]
3 Database Maintenance
4 Web Assistant
5 Full-Text
6 Log Shipping
7 Database Engine Tuning Advisor
10 REPL-Distribution
11 REPL-Distribution Cleanup
12 REPL-History Cleanup
13 REPL-LogReader
14 REPL-Merge
15 REPL-Snapshot
16 REPL-Checkup
17 REPL-Subscription Cleanup
18 REPL-Alert Response
19 REPL-QueueReader
20 Replication
98 [Uncategorized]
99 [Uncategorized]
*/
--a.run_time, a.*
from msdb.dbo.sysjobhistory a
inner join msdb.dbo.sysjobs b on a.job_id=b.job_id
where b.name='PCDBI'
order by run_date DESC,step_id Asc
作业的执行状态run_status:
0 = 失败
1 = 成功
2 = 重试
3 = 取消
4 = 正在进行
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- author : p.c.w.l
-- source : www.sqlstudy.com
-- create : 2008-01-01
-- descr : a simple sql script to view sql server jobs run status
--------------------------------------------------------------------------------
select category = jc.name,
category_id = jc.category_id,
job_name = j.name,
job_enabled = j.enabled,
last_run_time = cast(js.last_run_date as varchar(10)) + '-' + cast(js.last_run_time as varchar(10)),
last_run_duration = js.last_run_duration,
last_run_status = js.last_run_outcome,
last_run_msg = js.last_outcome_message + cast(nullif(js.last_run_outcome,1) as varchar(2)),
job_created = j.date_created,
job_modified = j.date_modified
from msdb.dbo.sysjobs j
inner join msdb.dbo.sysjobservers js
on j.job_id = js.job_id
inner join msdb.dbo.syscategories jc
on j.category_id = jc.category_id
where j.enabled = 1
and js.last_run_outcome in (0,1,3,5) -- 0:Fail 1:Succ 3:Cancel 5:First run
and jc.category_id not between 10 and 20 -- repl
/*
category_id name
0 [Uncategorized (Local)]
1 Jobs from MSX
2 [Uncategorized (Multi-Server)]
3 Database Maintenance
4 Web Assistant
5 Full-Text
6 Log Shipping
7 Database Engine Tuning Advisor
10 REPL-Distribution
11 REPL-Distribution Cleanup
12 REPL-History Cleanup
13 REPL-LogReader
14 REPL-Merge
15 REPL-Snapshot
16 REPL-Checkup
17 REPL-Subscription Cleanup
18 REPL-Alert Response
19 REPL-QueueReader
20 Replication
98 [Uncategorized]
99 [Uncategorized]
*/
相关文章推荐
- python判断一个进程是否正在运行
- 如何用命令行去Disable一个计划任务?带如何判断这个计划任务是否正在运行?必须是不在运行时才能Disable它。
- windows上如何判断一个进程是否正在运行
- 如何判断一个服务是否正在运行
- Android应用开发判断一个Activity是否正在运行
- Java SE作业:判断一个字符串是否是视频文件
- VB程序怎么判断另一个程序是否正在运行?
- Inno Setup安装、卸载时判断是否程序正在运行
- 如何判断一个线程是否正在执行
- C# WinForm 判断程序是否已经在运行,且只允许运行一个实例,附源码
- Delphi 中实现判断某个外部程序是否运行(如果运行则执行一个命令否则执行一个命令)
- Inno 4000 Setup安装、卸载时判断是否程序正在运行,安装完成时自动打开网页的脚本
- 【Android】Android中判断后台服务是否正在运行
- 第二周作业 判断一个数是否为质数
- 如何判断一个文件是否正在被使用
- Android高手之路之获取正在运行的service,以及判断某个service是否正在运行
- innosetup 安装前、卸载前判断是否有进程正在运行<转>
- 用守护进程来判断一个进程是否运行
- SWF运行时判断两个DisplayObject是否同个类型,属于flash professional库中的同一个元件
- 判断是否有全屏程序正在运行(C#)