"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

February 17, 2010

TSQL Tip of the day

Proactively raise an alert if my SQL agent job runs beyond certain time. For Querying Jobs and status you can use below query. From the job running time we can raise alert accordingly

SELECT DATEDIFF(MINUTE,ja.start_execution_date,GETDATE())
FROM msdb.dbo.sysjobactivity ja
INNER JOIN msdb.dbo.sysjobs j ON ja.job_id = j.job_id
WHERE j.name like '%JOBNAME%'
AND last_executed_step_date IS NULL

Related Read - Determine the current status of a SQL Server Agent job

Happy Reading!!

No comments: