Monday, 11 November 2013

SQL Query to START SQL Job

CREATE PROC [dbo].[SP_Start_Job]
(
    @JobName nvarchar(255) = 'BI Load For DFG'
)
AS
BEGIN
DECLARE @StartDate datetime
DECLARE @StopedDate datetime
    SELECT
        @StartDate = a.start_execution_date
        ,@StopedDate = a.stop_execution_date
    FROM [msdb].[dbo].[sysjobactivity] a
    JOIN [msdb].[dbo].[sysjobs] j
    on a.job_id = j.job_id
    where j.name =@JobName
   
    if(@StopedDate is not null)
    BEGIN
    EXEC msdb.dbo.sp_start_job @JobName;
    END
END

No comments:

Post a Comment