title: CASE statement inside OR inside AND in SQL
body: <pre><code>RES as 
  (
  SELECT code , payement,
  sum(A.ALLPAYMENT) as ACTUAL_PAYMENT,
  A.NAME
  FROM FINANCES A 
  WHERE payement= '6396'   
  and (ENDDATE&gt;=  CURRENT_TIMESTAMP) 
  and (BILLREFRENCE&lt;&gt; '' or 
  
  (case when (    CONVERT (int, (select BILLTIME from MYCALENDAR CL
                                  where CL.code = A.code and CL.NAME= 
  A.NAME
                                )  
                           )
                 &gt; CONVERT (INT, REPLACE( CONVERT(VARCHAR(8), GETDATE(), 108), 
                 ':', '' ) )  
              ) then LEVEL in ('300', '100', '404')
                else
                  LEVEL in ('300','404')
  )
  
  
   )
  GROUP BY code, payement, A.NAME)
  </code></pre>
  
  <p>the OR condition needs to be either " OR LEVEL in ('300', '100', '404') " or
   " OR LEVEL in ('300', '404') "
  if the current systemtime is greater than the BILLTIME  it's LEVEL in ('300','404') if not, it's  LEVEL in ('300', '100', '404')</p>
  
  <p>PS : BILLTIME is in the format of military time "130000", hence the conversions. </p>