Solved

How do I determine SQL Agent jobs active?

Posted on 2002-06-19
2
986 Views
Last Modified: 2008-01-09
SQL 7 Agent runs enabled jobs, at their appropriate times (or on request).  At any moment in time from zero thru N jobs could currently be active.  I would like to be able to run a query which would provide me with the information on what jobs are currently running when I submit the query.  Following is a view I tried creating to give me the info, but it does not appear to work.  I can create a SQL Agent Job which simply does a "waitfor" for 60 seconds, start it manually, then run the below.  The running/active job is not detected by my query.


CREATE VIEW What_jobs_are_running
AS
SELECT top 30 name,
       case b.run_status
       when 0 then 'failed'
       when 1 then 'succeeded'
       when 2 then 'retry'
       when 3 then 'canceled'
       when 4 then 'in progress'
       end
       as 'run status',
       b.sql_severity as 'err severity',
       b.run_date as 'run date',
       b.step_name, b.server,
       b.message as 'error message'
FROM msdb..sysjobs a  inner join sysjobhistory b on a.job_id = b.job_id
WHERE name like '%' and b.run_status = 4
order by b.run_date desc, a.name asc

I am not asking for the above code to be debugged.

I simply want to know how to query to find out what SQL Agent jobs are running/active.

TIA


0
Comment
Question by:solart
2 Comments
 
LVL 2

Accepted Solution

by:
bronwyn_black earned 100 total points
ID: 7094458
Hi,

This should work:

sp_help_job NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1

where the last param:
-- 1 = Executing, 2 = Waiting For Thread, 3 = Between Retries, 4 = Idle, 5 = Suspended, 6 = [obsolete], 7 = PerformingCompletionActions

Regs,

BB.
0
 
LVL 1

Author Comment

by:solart
ID: 7096157
Verified that solution actually works.  Thanks.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how the fundamental information of how to create a table.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now