title: Handling error from one stored procedure into another in Sybase ASE 15.0
body: <p>I need to execute a password reset on a Sybase ASE dataserver based on certain conditions:</p>
  
  <pre><code>if validations_here
  begin
      exec sp_password 'sso_passw', 'new_passw', @userid
  end
  </code></pre>
  
  <p><code>sp_password</code> might raise some errors, e.g. <em>10316 - "New password supplied is the same as the previous password"</em>. Although I couldn't find any documentation, I think they shouldn't be fatal errors and it should be possible to emulate them with <code>raiserror</code>.</p>
  
  <p>Since it would be easier for the caller to handle it that way, I would like to get the error code and return it as part of a resultset, so I thought about SELECTing @@error. My code is as follows (I transcribed only those parts I think are relevant to the problem):</p>
  
  <pre><code>create procedure sp_desbloc_blanqueo_usr    
      @userid sysname,        
      @sso_pass varchar(20),  
      @new_pass varchar(20)   
  as
  begin
      declare @ret_code int
      declare @ret_msg varchar(100)
      declare @myerror int
  
      select @ret_code = 0, @ret_msg = 'OK'
  
      exec sp_password @sso_pass, @new_pass, @userid
      set @myerror = @@error 
      if @myerror &lt;&gt; 0
      begin
          select @ret_code = @myerror, @ret_msg = 'Error occurred changing password' 
          -- It would be nice to have the actual error message as well
          goto fin
      end
  
      fin:
      select @ret_code as ret_code, @ret_msg as ret_msg
  end
  </code></pre>
  
  <p>However, whenever I execute the stored procedure, I get 0 as <code>ret_code</code> and OK as <code>ret_msg</code> (even if parameters to <code>sp_password</code> are wrong).</p>
  
  <p>How can I "catch" the error code of <code>sp_password</code> from my stored procedure?</p>