SQL Server : IF condition not working in stored procedure
<p>I have this condition in my stored procedure to determine which <code>WHERE</code> clause to use:</p>

<pre><code>IF (@communityDesc = 'All Areas')
BEGIN
    WHERE V_CONSTAT_ACTUAL_DATES.AREA_DESC IN (SELECT name 
                                               FROM dbo.splitstring(@communityDesc)) 
      AND V_CONSTAT_ACTUAL_DATES.DATE_TO_END &gt;= GETDATE()
END
ELSE
BEGIN
    WHERE V_CONSTAT_ACTUAL_DATES.DATE_TO_END &gt;= GETDATE()
END
ORDER BY V_CONSTAT_ACTUAL_DATES.DATE_TO_END
</code></pre>

<p>but I get a long list of errors:</p>

<blockquote>
  <p>Msg 156, Level 15, State 1, Procedure GetProductionSchedule, Line 256<br>
  Incorrect syntax near the keyword 'WHERE'.</p>
  
  <p>Msg 156, Level 15, State 1, Procedure GetProductionSchedule, Line 256<br>
  Incorrect syntax near the keyword 'AND'.</p>
</blockquote>

<p>What am I doing wrong?</p>