I'm using an NVL function in my WHERE clause like this.
... AND NVL(FIRST_DATE, SECOND_DATE) BETWEEN (SYSDATE - 7) and SYSDATE
What I'm doing is this: If FIRST_DATE is null then use the SECOND_DATE for comparison. The problem with this is that it prevents index usage on the column first_date or second_date. So I rewrote the condition into this:
... AND
((FIRST_DATE BETWEEN (SYSDATE-7) AND SYSDATE)
OR
(FIRST_DATE IS NULL AND SECOND_DATE BETWEEN (SYSDATE-7) AND SYSDATE))
I tested it by running it with different dates and it always returned the same results as with the NVL Function. But I want to make sure and check if I didn't miss any exceptions where the result may differ. Can anyone confirm that what I did is semantically equivalent to the NVL Function?