Created
November 1, 2012 20:50
-
-
Save kmoormann/3996459 to your computer and use it in GitHub Desktop.
Check if SSIS Job is Running
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @JOB_NAME SYSNAME = N'Daily update of indexes & statistics'; | |
IF NOT EXISTS( | |
select 1 | |
from msdb.dbo.sysjobs_view job | |
inner join msdb.dbo.sysjobactivity activity on job.job_id = activity.job_id | |
where | |
activity.run_Requested_date is not null | |
and activity.stop_execution_date is null | |
and job.name = @JOB_NAME | |
) | |
BEGIN | |
PRINT 'Starting job ''' + @JOB_NAME + ''''; | |
EXEC msdb.dbo.sp_start_job @JOB_NAME; | |
END | |
ELSE | |
BEGIN | |
PRINT 'Job ''' + @JOB_NAME + ''' is already started '; | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks to http://gallery.technet.microsoft.com/scriptcenter/Check-if-a-SQL-Server-75b889b4