Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 find out if a job is running or when it last ran

Author  Topic 

Bill_C
Constraint Violating Yak Guru

299 Posts

Posted - 2012-02-09 : 02:46:24
I'm trying to check if a particular job is running, and if it is not, when it last ran so I can use this info to decide whether the job needs to run again (based on if we have recieved new data since the job was last run).

sort of thing I'm looking for goes along the lines of:-

select COUNT(1) from msdb.dbo.sysjobhistory a
inner join msdb.dbo.sysjobs b on
a.job_id = b.job_id
where b.name = 'myjobname'
and CAST(a.run_date as date) = '09 fed 2012'
and CAST(run_time as time(0)) > '01:00'


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-09 : 14:22:11
see

http://sqlconcept.com/2011/06/25/how-to-query-currently-running-sql-server-agent-jobs/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -