Solved

How do I determine SQL Agent jobs active?

Posted on 2002-06-19
2
984 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
Comment Utility
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
Comment Utility
Verified that solution actually works.  Thanks.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

744 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

18 Experts available now in Live!

Get 1:1 Help Now