title: Conditional Where Clause Based on Sysdate?
body: <p>I'm creating a query that will be run twice a month:</p>
  
  <ol>
  <li><p>On the 5th of the month looking at billing days 16-last day of the month of the previous month.</p>
  
  <pre><code>datepart(dd,h.BILLED_DATE) &gt; 15    
  DATEPART(mm, h.billed_date) = DATEPART(mm,dateadd(m,-1,getdate()))
  and DATEPART(yyyy, h.billed_date) = DATEPART(yyyy,dateadd(m,-1,getdate()))
  </code></pre></li>
  <li><p>On the 20th of the month looking at billing days of 1-15 of the same month.</p>
  
  <pre><code>datepart(dd,h.BILLED_DATE) &gt;= 1
  and datepart(dd,h.BILLED_DATE) &lt; 16
  and DATEPART(mm, h.BILLED_DATE) = DATEPART(mm,GETDATE())
  and DATEPART(yyyy, h.BILLED_DATE) = DATEPART(yyyy,GETDATE()))
  </code></pre></li>
  </ol>
  
  <p>These work independently in the where clause.  When I try to combine them in a case statement in the where clause, however, I'm getting errors galore, starting with the first inequality after the "then."</p>
  
  <pre><code>Where
    Case 
      when datepart(dd,getdate()) &gt; 15 
        then [2 above]
        else [1 above]
    End
  </code></pre>
  
  <p>Cure my ignorance.</p>