title: SQL IF statement Issue
body: <p>What's wrong with my SQL statement?</p>
  
  <pre><code>ALTER PROCEDURE prGetDocById
      @Nbr varchar(100),
      @Type uniqueidentifier,
      @TotalRecord int output
  AS
  BEGIN
      IF(@Type is null)
      BEGIN
      (
          SELECT @TotalRecord = COUNT(Category) FROM Document where Nbr = @Nbr and 
              Type = (case when @Type IS not null then @Type else null end) 
          SELECT * from Document
      )
      end
      else
      begin
      (
          ...
      )
      end
  end
  </code></pre>
  
  <p>it gives me this error:</p>
  
  <blockquote>
    <p>Msg 156, Level 15, State 1, Procedure prGetDocById, Line 12<br>
    Incorrect syntax near the keyword 'SELECT'.<br>
    Msg 102, Level 15, State 1, Procedure prGetDocById, Line 13<br>
    Incorrect syntax near ')'.<br>
    Msg 102, Level 15, State 1, Procedure prGetDocById, Line 19<br>
    Incorrect syntax near ')'.</p>
  </blockquote>
  
  <p>I want to start with <code>IF</code> statement and need to return the output too, so there will be two select statement in my statement.</p>
  
  <p>If I write it without <code>IF</code> statement, everything is OK.</p>