Link to home
Start Free TrialLog in
Avatar of solart
solart

asked on

How do I determine SQL Agent jobs active?

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


ASKER CERTIFIED SOLUTION
Avatar of bronwyn_black
bronwyn_black

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of solart
solart

ASKER

Verified that solution actually works.  Thanks.