A small stored procedure that tells whether a job is running or not.<br /><br /><font face="Courier New">CREATE <img src='/community/emoticons/emotion-4.gif' alt=';P' />ROCEDURE dbo.IsJobRunning<br />(<br /> @job_name varchar(255),<br /> @is_job_running int OUTPUT<br />)<br />AS<br /> BEGIN<br /> DECLARE @job_id uniqueidentifier <br /> <br /> CREATE TABLE #xp_results <br /> (<br /> job_id uniqueidentifier NOT NULL,<br /> last_run_date int NOT NULL,<br /> last_run_time int NOT NULL,<br /> next_run_date int NOT NULL,<br /> next_run_time int NOT NULL,<br /> next_run_schedule_id int NOT NULL,<br /> requested_to_run int NOT NULL, -- BOOL<br /> request_source int NOT NULL,<br /> request_source_id sysname COLLATE database_default NULL,<br /> running int NOT NULL, -- BOOL<br /> current_step int NOT NULL,<br /> current_retry_attempt int NOT NULL,<br /> job_state int NOT NULL<br />  <img src='/community/emoticons/emotion-5.gif' alt='' /><br /> <br /> SELECT @job_id = sj.job_id <br /> FROM msdb.dbo.sysjobs sj<br /> WHERE sj.name = @job_name<br /> <br /> INSERT INTO #xp_results<br /> EXEC master.dbo.xp_sqlagent_enum_jobs 1, ''<br /><br /> SELECT @is_job_running = running<br /> FROM #xp_results<br /> WHERE job_id = @job_id<br /> END</font id="Courier New"><br /><br />After a few days of struggling I think this is the best way to do it. But I am waiting for your comments.<br /><br />--<br /><br /><i>"Recommended By Dr. Audioscrobbler." <br /<a target="_blank" href=http://www.last.fm/user/chopeen/>http://www.last.fm/user/chopeen/</a></i>
if I am correct sp_help_job @execution_status = 1 will also give the same result ---------------------------------------- Cast your vote http://www.geocities.com/dineshasanka/sqlserver05.html http://spaces.msn.com/members/dineshasanka
You are right, but it won't return this information as an OUTPUT parameter. Which means that you cannot assign it to a variable. -- "Recommended By Dr. Audioscrobbler." http://www.last.fm/user/chopeen/