title: Return value from a stored proc on error
body: <p>I have an sp in SQL Server that when errors returns -4</p>
  
  <p>What does -4 mean? Is there a table somewhere explaining what the possible return values are?</p>
  
  <hr>
  
  <p>There must be some standard</p>
  
  <p>For example</p>
  
  <pre><code>declare @RetVal int  
  EXEC @RetVal = stpTest  
  select @RetVal
  </code></pre>
  
  <p>where stpTest is "SELECT 1/0" returns -6. </p>
  
  <p>-6 must mean something!</p>
  
  <hr>
  
  <p>The sp that returned -4 only has UPDATE and SELECT INTO statements in it.</p>
  
  <p>At no point does it do 'SELECT -4' so how can I "find out what -4 means in that particular stored procedure"?</p>
  
  <p>Also, if there is no standard then why does a divide by zero error always return -6?</p>
  
  <hr>
  
  <p>If you have an sp that does not return anything i.e. it doesn't have any select statements in it and you do:    </p>
  
  <pre><code>declare @RetVal int  
  EXEC @RetVal = yourSPName  
  </code></pre>
  
  <p>Then @RetVal will have a value of 0. </p>
  
  <p>If there is an error then @RetVal will be a value other then zero, for example if the only thing your sp does is "SELECT 1/0" then @RetVal will be -6.</p>
  
  <p>Try it and see</p>
  
  <p>My question is what do these return values mean? They must have some logical meaning! </p>