Execute a SQL Agent job Via Stored Procedure

  • Hi,

    Does anyone knows a handy stored procedure to execute a sql agent job with return result of the sql agent job?
    I have to add few logic here to check sql job history checks and based on the output of the SQL agent job, I would like my result. Please let me know if possible.

    Below is my syntax.

    CREATE PROC [dbo].[SPXYZ]
    WITH EXECUTE AS 'dbo'
    AS
    Begin
    Begin Try
    EXEC msdb.dbo.sp_start_job N'ABCSQLAgentJob';
    End Try
    Begin Catch
    PRINT 'Full Backup failed. Please call On call DBA Support to resolve this issue.'
    End Catch
    End

  • hello_san - Friday, January 27, 2017 1:05 PM

    Hi,

    Does anyone knows a handy stored procedure to execute a sql agent job with return result of the sql agent job?
    I have to add few logic here to check sql job history checks and based on the output of the SQL agent job, I would like my result. Please let me know if possible.

    Below is my syntax.

    CREATE PROC [dbo].[SPXYZ]
    WITH EXECUTE AS 'dbo'
    AS
    Begin
    Begin Try
    EXEC msdb.dbo.sp_start_job N'ABCSQLAgentJob';
    End Try
    Begin Catch
    PRINT 'Full Backup failed. Please call On call DBA Support to resolve this issue.'
    End Catch
    End

    Duplicate post.
    Call SQL agent job Via Stored Procedure

    Hello_san - Please post to just one forum. It gets a bit confusing and efforts are duplicated when there is more than one post for a question.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply