IF OBJECT_ID('tempdb.dbo.# RunningJobs') IS NOT NULL
DROP TABLE #RunningJobs
CREATE TABLE #RunningJobs
(
Job_ID UNIQUEIDENTIFIER,
Last_Run_Date INT,
Last_Run_Time INT,
Next_Run_Date INT,
Next_Run_Time INT,
Next_Run_Schedule_ID INT,
Requested_To_Run INT,
Request_Source INT,
Request_Source_ID VARCHAR(100),
Running INT,
Current_Step INT,
Current_Retry_Attempt INT,
State INT
)
INSERT INTO #RunningJobs
EXEC master.dbo.xp_sqlagent_enum_ jobs 1,garbage
SELECT j.job_id, j.name AS JobName,
(CASE WHEN next_run_date=0 THEN '[Not scheduled]' ELSE CONVERT(VARCHAR,msdb.dbo.agent _datetime(r.Next_Run_Date, r.Next_Run_Time)) END) as JobStart
FROM #RunningJobs r
JOIN msdb.dbo.sysjobs j on r.Job_ID = j.job_id
WHERE r.Running = 1 -- running now
ORDER BY j.name, r.next_run_date, r.next_run_time
IF OBJECT_ID('tempdb.dbo.# RunningJobs') IS NOT NULL
DROP TABLE #RunningJobs
No comments:
Post a Comment