how do i read this sql code

Posted on 2012-09-17
Last Modified: 2012-09-17

I think i'm having a brain cramp. but the exec @failing   stored proc   ..output  
followed by if @failing > 0

 is throwing me off here.  Can someone explain how to "read" the code .    
Is the output stATEMENT rEPLACING THE @FAILING WITH THE return code being st in the stored proc if it errors out?

         set @LocalProcedure = 'up_XL_zUpdateStgSiteToSite'
      exec @Failed = JabilDBImport.dbo.up_zUpdateImportJobEvent
         @ImportJobID = @ImportJobID,
         @Event = 'Update Site',
         @StartDTS = @CreateUpdateDTS,
         @AddMessage = 'Started',
         @Status = 'Processing...',
         @EndDTS = null
      exec @Failed = up_XL_zGetDataSourceID @ImportJobID, @DataSourceID OUTPUT
      if @Failed <> 0
          -- ams 7/9/02 c1/a2
          set @ErrorMessage = @LocalProcedure + ' - Error calling up_XL_zGetDataSourceID'
          return 1
Question by:rschmehl
    LVL 19

    Assisted Solution

    by:Ken Butters
    The @Failed is being set to the return code of the called function.

    if @Failed<> 0 means if @Failed is NOT zero.

    A zero return code usually means success... so it is checking for non-zero... meaning failure.

    In your original comment you referrred to @Fail > 0 ... which is different... @Fail > 0 would be checking if the return code is Greater than zero... "<>" means not equal to.
    LVL 25

    Assisted Solution

    And the output parameter is not replacing the value of @Failed. The value of the output parameter is stored in @DataSourceID.

    Author Comment

    I'm not sure I understand the exec @Failed proc_ABC , why put the @failedin at all when you are exec Proc_abc?
    LVL 25

    Accepted Solution

    This is just to raise your custom error. You can leave without it as well. You will get a system defined error. But this check will help you if you are doing link server (remote server) call. In that case, even if the procedure fails, the execution of the query mayn't be stopped which will hurt the consistency of the data.

    Author Closing Comment

    Thanks alot

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now