title: Stored Procedure error - incorrect syntax near else
body: <p>I'm working on my first stored procedure, and it's showing an error at the else (where I have a comment at the else below). If anyone knows how I can fix the error, I'd appreciate it. I've tried looking online, and I think it may have to do with my begin/end and if/else positioning.  I'm having trouble finding a similar example though.</p>
  
  <pre><code>SET ANSI_NULLS ON
  GO
  
  SET QUOTED_IDENTIFIER ON
  GO
  
  CREATE procedure [dbo].[SPName]
      @userid NVARCHAR(51)
  AS 
      SET NOCOUNT ON
  
      DECLARE @return_status  INT
  
      IF @userid IS NULL OR @userid = 0
      BEGIN
          --fail
          SET @return_status = 1
      END
  
      IF  @return_status &lt;&gt; 1
      BEGIN
          IF EXISTS (SELECT login
                     FROM dbo.user_table
                     WHERE (@userid = login))
          --continue because its a good user
          ELSE  
              -- this is where it doesn't like the else
              SET @return_status = 1
      END
  
      BEGIN
          UPDATE dbo.U_MEMBER
          SET dbo.U_MEMBER.inac = 1,
              dbo.U_MEMBER.reg = @userid
          FROM dbo.U_MEMBER
          WHERE U_MEMBER.VF = 'REV'
      END
  
      RETURN 0
  </code></pre>