Subject Re: [firebird-support] How can I correctly write this WHERE
Author livius
Hi,
 
is this your real query? I ask, because  below WHERE can be not intentionaly written by OR
 
WHERE     (
                    heir.iaccttreeid = 47
          AND       cast(tsi.tdt AS date) < '2018-04-01' )
OR        (
                    heir.iaccttreeid <> 47
          AND       cast(tsi.tdt AS date) BETWEEN '2018-03-01' AND       '2018-03-31' )
AND       tsi.cdoctype NOT LIKE 'PROFORMA%'
AND       tsi.cdoctype NOT LIKE 'CANCELLED%'
AND       ssifooter.cdrcr IN ('DR',
                              'CR')

i suppose you need more parenthesis:
 
WHERE    
(
        (
            heir.iaccttreeid = 47
            AND
            cast(tsi.tdt AS date) < '2018-04-01'
        )
    OR       
        (
            heir.iaccttreeid <> 47
            AND      
            cast(tsi.tdt AS date) BETWEEN '2018-03-01' AND       '2018-03-31'
        )
)       
AND       tsi.cdoctype NOT LIKE 'PROFORMA%'
AND       tsi.cdoctype NOT LIKE 'CANCELLED%'
AND       ssifooter.cdrcr IN ('DR',
                              'CR')

 
regards,
Karol Bieniaszewski