• Here is the code for pr_RunAgentJob:

    Sorry about the non-inclusion

    CREATE PROCEDURE [dbo].[pr_RunAgentJob]

    (

    @JobName VARCHAR(200)

    )

    AS

    /*

    This procedure is a wrapper for the sp_start_job stored procedure.

    It tests whether the job is running before allowing the job to be re-run

    */

    DECLARE @TestExists TINYINT

    SELECT@TestExists = COUNT(*)

    FROMmsdb.dbo.sysjobactivity JA inner join msdb.dbo.sysjobs JO

    ONJA.Job_ID = JO.Job_ID

    WHERE JO.Name = @JobName

    AND start_execution_date IS NOT NULL

    AND Stop_execution_date IS NULL

    IF @TestExists = 0

    BEGIN

    EXEC msdb.dbo.sp_start_job @JobName

    RETURN 0 -- job called OK

    END

    ELSE

    BEGIN

    RETURN 1 -- Job running

    END