title: Use CASE in WHERE clause - Data Parameters Sql Server
body: <p>I'm trying to verify the example, if the date is null pick a date from another field. Below the query:</p>
  
  <pre><code>SELECT
      *
  FROM
      OrderPublish OP
      INNER JOIN Advertising AD ON
          AD.IdOrderPublish = OP.IdOrderPublish
      INNER JOIN Client Cli ON
          Cli.IdClient = OP.IdClient
      LEFT JOIN AdvertisingInserted AII ON
          AD.IdAdvertisingInserted = AII.IdAdvertisingInserted
      LEFT JOIN TypeProduct TP ON
          AII.IdTypeProduct = TP.IdTypeProduct
      INNER JOIN Publication PUB ON
          PUB.IdAdvertisingInserted = AII.IdAdvertisingInserted
  WHERE
      TP.IdTypeProduct in (5,7)
      AND CASE WHEN PUB.DtIni IS NULL
          THEN
              OP.DtInc &gt;= Isnull('08/18/2013', OP.DtInc)
          ELSE
              PUB.DtIni &gt;= Isnull('08/18/2013', PUB.DtIni)
          END
      AND CASE PUB.DtFinal WHEN NULL
          THEN
              OP.DtInc &lt;= Isnull('08/23/2013', OP.DtInc)
          ELSE
              PUB.DtFinal &lt;= Isnull('08/23/2013', PUB.DtFinal)
          END
  </code></pre>