Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SP to check if a job is running?

Author  Topic 

Mmats
Starting Member

47 Posts

Posted - 2005-07-12 : 11:51:54
Is there a stored procedure or another way to find out if a certain job is currently running?

nathans
Aged Yak Warrior

938 Posts

Posted - 2005-07-12 : 12:08:52
Use this to list all statuses... filter out what you need.

Look into sysJobs, sysJobHistroy, etc. tables in BOL.


Use msdb
go

select distinct
j.Name 'Job Name',
case h.run_status
when 0 then 'Failed'
when 1 then 'Successful'
when 3 then 'Cancelled'
when 4 then 'In Progress'
end as 'JobStatus'
from sysJobHistory h inner join sysJobs j
on j.job_id = h.job_id
where h.run_date = (select max(hi.run_date) from sysJobHistory hi where h.job_id = hi.job_id)
order by 1


Nathan Skerl
Go to Top of Page

Mmats
Starting Member

47 Posts

Posted - 2005-07-12 : 12:36:43
I should have mentioned these jobs are part of a maintenance plan so their history isnt written to sysjobs or sysjobhistory. Looks like their isnt any kind of run status field in sysdbmaintplan_history either. Know anything about the SP xp_sqlagent_enum_jobs?
Go to Top of Page

Mmats
Starting Member

47 Posts

Posted - 2005-07-12 : 13:24:28
Disregard my above post, thought maintenance plan jobs werent written to those tables but they are. However I just found xp_sqlagent_enum_jobs , which i think would be best. Thanks
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2005-07-12 : 13:58:47
Ah yes, its undocumented proc called by sp_help_jobs



Nathan Skerl
Go to Top of Page
   

- Advertisement -