title: SQL Server 2000: How to exit a stored procedure?
body: <p>How can I exit in the middle of a stored procedure?</p>
  
  <p>I have a stored procedure where I  want to bail out early (while trying to debug it). I've tried calling <code>RETURN</code> and <code>RAISERROR</code>, and the sp keeps on running:</p>
  
  <pre><code>CREATE PROCEDURE dbo.Archive_Session @SessionGUID uniqueidentifier AS
  
      print 'before raiserror'
      raiserror('this is a raised error', 18, 1)
      print 'before return'
      return -1
      print 'after return'
  
  [snip]
  </code></pre>
  
  <p>I know it keeps running because I encounter an error further down. I don't see any of my <strong>prints</strong>. If I comment out the bulk of the stored procedure:</p>
  
  <pre><code>CREATE PROCEDURE dbo.Archive_Session @SessionGUID uniqueidentifier AS
  
      print 'before raiserror'
      raiserror('this is a raised error', 18, 1)
      print 'before return'
      return -1
      print 'after return'
  
     /*
       [snip]
     */
  </code></pre>
  
  <p>Then I don't get my error, and I see the results:</p>
  
  <pre><code>before raiserror
  Server: Msg 50000, Level 18, State 1, Procedure Archive_Session, Line 5
  this is a raised error
  before return
  </code></pre>
  
  <p>So the question is: how do I bail out of a stored procedure in SQL Server?</p>