user2930462 user2930462 - 1 month ago 17
Android Question

IF Condition in SQLite

how can i convert this code in sqlite query

Select *
from TABLE
where id = 1 AND
IF(RECEIPT_MODE = 'MANUAL', DATE(a.MANUAL_COLLECTION_DATE) = DATE('2015-02-10 09:12:00'), DATE(a.TPAY_ISSUED_DATE) = DATE('2015-02-10 09:12:00'))


it works in my navicat but when i try these in SQLite 'IF' is not supported.

Answer

Don't use if(). Just use logic:

select *
from TABLE
where id = 1 AND
      ( (receipt_mode = 'MANUAL' and DATE(a.MANUAL_COLLECTION_DATE) = DATE('2015-02-10 09:12:00') or
        (receipt_mode <> 'MANUAL' and DATE(a.TPAY_ISSUED_DATE) = DATE('2015-02-10 09:12:00'))
      );
Comments