title: Conditional WHERE statement SQL Server
body: <p>I would like to create a SP that will return all <code>Country</code> rows unless a <code>CountryID</code> is provided as a parameter. Here is how I imagined it might work, but it doesn't like it.</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[usp_return_countries]
      @CountryID AS INT = 0
  AS
  BEGIN
          SELECT *
          FROM Countries
          WHERE Active = 1
  
          IF @CountryID &gt; 0 BEGIN
              AND @CountryID = CountryID
          END
  
  END
  </code></pre>
  
  <p>Thank you</p>
  
  <p>P.S. I thought there might be a better way than simply repeating the entire SELECT statement based on the said condition.</p>