Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

how do i read this sql code


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
  • 2
  • 2
3 Solutions
Ken ButtersCommented:
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.
And the output parameter is not replacing the value of @Failed. The value of the output parameter is stored in @DataSourceID.
rschmehlAuthor Commented:
I'm not sure I understand the exec @Failed proc_ABC , why put the @failedin at all when you are exec Proc_abc?
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.
rschmehlAuthor Commented:
Thanks alot

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now