title: SQL Server 2008 WHERE clause with CASE / WHEN and NULL value
body: <p>I'm trying to write something like :</p>
  
  <pre><code>SELECT *
  FROM MyTable m
  WHERE m.Category = CASE WHEN @Category IS NULL THEN m.Category ELSE @Category END
  </code></pre>
  
  <p>Basically, I need lines where <code>m.Category</code> equals <code>@Category</code> if this one has a value ; else, I need all lines.</p>
  
  <p>BUT if <code>m.Category</code> has <code>NULL</code> value, the line is NOT send back because SQL needs something lile <code>WHERE m.Category IS NULL</code> and not <code>WHERE m.Category = NULL</code>.</p>
  
  <p>So, how could I modify my request to tell to SQL : "I need ALL lines if <code>@Category</code> is null (even lines where <code>m.Category</code> is null), but if <code>@Category</code> has a value, I just need lines where <code>m.Category</code> matches <code>@Category</code> ?</p>