Return Code

  • Hi,

       i need to know how can i get the return code ='True' if it is executed successfully and return code ='False'

      if it fails.

     

     

     

    set

    ANSI_NULLS ON

    set

    QUOTED_IDENTIFIER ON

    go

     

    -- =============================================

    -- Author: <Author,,Name>

    -- Create date: <Create Date,,>

    -- Description: <Description,,>

    -- =============================================

    ALTER

    PROCEDURE [dbo].[Load_Audit_Excel]

    AS

    BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNT ON;

    Exec Load_Audit_Excel.Sp_Start_job @Audit= 'Audit Data Load'

    END

  • declare @retval int

    exec @reval = Load_Audit_Excel.Sp_Start_job @Audit = 'Audit Data Load'

    select @retval

    If @retval = 0 then successfull, else failure.

    Try reading BOL, all of this is there.

  • i need help on this i am getting the following error message

     

    Msg 156, Level 15, State 1, Procedure Load_Audit_Excel, Line 22

    Incorrect syntax near the keyword 'Then'.

     

     

     

    set ANSI_NULLS ON

    set QUOTED_IDENTIFIER ON

    go

     

     

    -- =============================================

    -- Author: <Author,,Name>

    -- Create date: <Create Date,,>

    -- Description: <Description,,>

    -- =============================================

    ALTER

    PROCEDURE [dbo].[Load_Audit_Excel]

    AS

    declare

    @retval int

    BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNT ON;

    exec @retval = Load_Audit_Excel.Sp_Start_job @Audit = 'Audit Data Load'

    select @retval

    If

    @retval = 0 Then

    Success

    Else

    Failure

    END

    IF

     

     

     

  • T-SQL doesn't use "IF-THEN-ELSE-END IF" syntax. You'll find our own flavor of IF in BOL under "IF ...ELSE".

  • This:  If @retval = 0 then successfull, else failure. was a comment telling you that if @retval = 0 then the stored procedure executed successfully, else it failed.

    Please try taking the time to read BOL.  You will find most of the answers to your questions there.

  • This:  If @retval = 0 then successfull, else failure. was a comment telling you that if @retval = 0 then the stored procedure executed successfully, else it failed.

    Please try taking the time to read BOL.  You will find most of the answers to your questions there.

  • can you tell me how to write the correct syntax

  • Yes, I could, but I won't.  maybe some one else will, but we aren't doing you any favors just giving you the answers.  You need to take the time to read BOL and learn some things on your own.  Give it a try, you may find it quite rewarding when you figure out something on your own instead of relying on others all the time.  I know I feel good when I solve a problem myself, but I also know when I need someone elses perspective.  Figuring out how to write an IF ELSE statement in SQL is one you should try yourself first by taking the time to read BOL.

  • OK i was able to get it but can i ask you something now.How can i get the return output code without an input parameter

     

    set

    ANSI_NULLS ON

    set

    QUOTED_IDENTIFIER ON

    go

     

     

    -- =============================================

    -- Author: <Author,,Name>

    -- Create date: <Create Date,,>

    -- Description: <Description,,>

    -- =============================================

    ALTER

    PROCEDURE [dbo].[Load_Audit_Excel]

     

    AS

    declare

    @retval int

    BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNT ON;

    exec @retval = Load_Audit_Excel.Sp_Start_job @Audit = 'Audit Data Load'

    select @retval

    IF

    @retval = 0

    BEGIN

    Return True

    END

    Else

    Return

    False

    END

  • I would recommend looking up the following in BOL:

    EXECUTE

    RETURN (both the T-SQL Reference and "Using RETURN")

    Note: I thought I should note that when I interview people, I throw all sorts of curveballs at them. I'm not looking for them to know ALL of the answers, but the one thing I expect for them to say when they don't know the answer is "I'm not sure, but that's what BOL is for". If BOL hasn't made it near the top of your most used applications list, then you're doing something wrong.

     

     

Viewing 10 posts - 1 through 9 (of 9 total)

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