Comment voir les jobs en cours dans SQL Serveur ?

0
68
SELECT  jb.name,  
            jb.originating_server ServerName,  
            ja.run_requested_date JobStartTime,  
            DATEDIFF(MINUTE, ja.run_requested_date, GETDATE()) as TimeElapsed_Minutes,  
            case when ja.last_executed_step_id is null  
                 then 'Step '+Cast (start_step_id as varchar(20)) +' ['+sstep.step_name+'] executing'  
                 else 'Step ' +Cast ( last_executed_step_id+1 as varchar(20))+' ['+ lstep.step_name  
                      + '] executing'   
            end CurrentStepID , sstep.step_name JobStartedfromStep  
            , Case ja.run_requested_source when 1 then 'SCHEDULER'  
                                   when 2 then 'ALERTER'  
                                   when 3 then 'BOOT'  
                                   when 4 then 'USER'  
                                   when 6 then 'ON_IDLE_SCHEDULE' else 'Unknown' end JobRunSource  
    FROM    msdb.dbo.sysjobs_view jb  
            INNER JOIN msdb.dbo.sysjobactivity ja ON jb.job_id = ja.job_id  
            INNER JOIN msdb.dbo.syssessions sess ON sess.session_id = ja.session_id  
            LEFT JOIN MSDB.DBO.sysjobsteps sstep ON sstep.step_id =start_step_id and sstep.job_id=jb.job_id  
            LEFT JOIN MSDB.DBO.sysjobsteps lstep ON lstep.step_id =last_executed_step_id + 1 and lstep.job_id=jb.job_id   
    WHERE   stop_execution_date IS NULL   
            AND run_requested_date IS NOT NULL

ou

 SELECT
 ja.job_id,
 j.name AS job_name,
 ja.start_execution_date, 
 ISNULL(last_executed_step_id,0)+1 AS current_executed_step_id,
 Js.step_name
FROM msdb.dbo.sysjobactivity ja 
LEFT JOIN msdb.dbo.sysjobhistory jh 
 ON ja.job_history_id = jh.instance_id
JOIN msdb.dbo.sysjobs j 
ON ja.job_id = j.job_id
JOIN msdb.dbo.sysjobsteps js
 ON ja.job_id = js.job_id
 AND ISNULL(ja.last_executed_step_id,0)+1 = js.step_id
WHERE ja.session_id = (SELECT TOP 1 session_id FROM msdb.dbo.syssessions ORDER BY agent_start_date DESC)
AND start_execution_date is not null
AND stop_execution_date is null;

LEAVE A REPLY

Please enter your comment!
Please enter your name here