title: CASE statement after WHERE then one of several values can be NULL?
body: <p>I have such select:</p>
  <pre><code>SELECT 
   * 
  FROM 
   Table Tb 
  WHERE
   Tb.LastModificationDate BETWEEN @StartDate And @EndDate 
   AND Tb.var1 = @var1
   AND Tb.var2 = @var2
  </code></pre>
  <p>And its possible that @var1 and @var2 can be null (or only one of them) so for now I have 3 selects for each case (real select is more complicated so I am providing example for simplify things) I am try to merge them into one select with CASE but have no luck so far - as cant understand how to include AND clause in case if one of vars are not null.
  I believe it should be something like that:</p>
  <pre><code> SELECT 
    * 
   FROM 
    Table Tb 
   WHERE
    Tb.LastModificationDate BETWEEN @StartDate And @EndDate 
    (CASE WHEN @var1 IS NOT NULL THEN (AND Tb.var1 = @var1)
          WHEN @var2 IS NOT NULL THEN (AND Tb.var2 = @var2)
    END);
  </code></pre>
  <p>any advice on that?</p>