Solved

How do I determine SQL Agent jobs active?

Posted on 2002-06-19
2
988 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

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…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

786 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