title: IF condition in SQL Server stored procedure
body: <p>Not sure what I am doing wrong here. Could you please correct me?</p>
  
  <p>I am writing this logic in my stored procedure but I get an error:</p>
  
  <pre><code>DECLARE @PERIOD AS VARCHAR(7)
  
  BEGIN
      IF(MONTH(GETDATE()) = 1 or MONTH(GETDATE()) = 2 or MONTH(GETDATE()) = 3)
      BEGIN
          SET @PERIOD = YEAR(GETDATE() + ' Q1'
      END
      ELSE IF(MONTH(GETDATE()) = 4 or MONTH(GETDATE()) = 5 or MONTH(GETDATE()) = 6)
      BEGIN
          SET @PERIOD = YEAR(GETDATE() + ' Q2'
      END
      ELSE IF(MONTH(GETDATE()) = 7 or MONTH(GETDATE()) = 8 or MONTH(GETDATE()) = 9)
      BEGIN
          SET @PERIOD = YEAR(GETDATE() + ' Q3'
      END
      ELSE IF (MONTH(GETDATE()) = 10 or MONTH(GETDATE()) = 11 or MONTH(GETDATE()) = 12)
      BEGIN
          SET @PERIOD = YEAR(GETDATE() + ' Q4'
      END
  END
  </code></pre>
  
  <p>Error is: </p>
  
  <blockquote>
    <p>Msg 156, Level 15, State 1, Line 6<br>
    Incorrect syntax near the keyword 'END'.</p>
    
    <p>Msg 156, Level 15, State 1, Line 10<br>
    Incorrect syntax near the keyword 'END'.</p>
    
    <p>Msg 156, Level 15, State 1, Line 14<br>
    Incorrect syntax near the keyword 'END'.</p>
    
    <p>Msg 156, Level 15, State 1, Line 18<br>
    Incorrect syntax near the keyword 'END'.</p>
  </blockquote>