title: Using IsNull() in a WHERE clause
body: <p>This query:</p>
  
  <pre><code>SELECT
      sc.ContactID
      , c.Price
      , p.ParkID
      FROM
          tblc c
          JOIN tblsc ON c.ID= sc.ID
          LEFT JOIN tblp p ON sc.ID= p.ID
      WHERE
          (stuff = stuff)
          AND (stuff = stuff)
  </code></pre>
  
  <p>Returns this:</p>
  
  <pre><code>ContactID    LeadSalePrice     ParkID
  -------------------------------------
      1           50             NULL
      2           60              22
  </code></pre>
  
  <p>Now, I am trying to set up another <code>AND</code> clause for <code>ParkID</code>.  But, I only want to execute this <code>AND</code> on rows where <code>ParkID</code> IS NOT NULL.  So, if on rows where <code>ParkID</code> IS NULL, we want to always keep those rows.  On rows where ParkID IS NOT NULL, we only want to keep those rows if <code>ParkID</code> matches the parameter.</p>
  
  <p>If @ParkID = 22, then return both rows.</p>
  
  <p>If @ParkID &lt;> 22, then only return the top row.</p>
  
  <p>If @ParkID = NULL, then return both rows.</p>
  
  <p>I've tried this:</p>
  
  <pre><code>SELECT
      sc.ContactID
      , c.Price
      , p.ParkID
  FROM
      tblc c
      JOIN tblsc ON c.ID= sc.ID
      LEFT JOIN tblp p ON sc.ID= p.ID
      WHERE 
          (stuff = stuff)
          AND (stuff = stuff)
          AND p.ParkID = 
              CASE WHEN p.ParkID IS NULL THEN 
                  NULL
             ELSE
                  @ParkID
              END
  </code></pre>
  
  <p>This doesn't work because the proper way to compare with null is not:</p>
  
  <pre><code>= NULL
  </code></pre>
  
  <p>It's</p>
  
  <pre><code>IS NULL
  </code></pre>
  
  <p>For the same reason (I assume), this doesn't work either:</p>
  
  <pre><code>AND p.ParkID = Isnull(p.ParkID, @ParkID)
  </code></pre>
  
  <p>How do I do this?</p>