Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Case statement to pull data between two date ranges ?

BobSandersDec 21 2017 — edited Dec 21 2017

Hello,

How can I pull the data from a table twice for 2 different date ranges 2 times in a month ? I need to pull the data on 16th of the current month and another at the end of the current month.

For example: If the current month date is 16 then I need to pull the data from the table where the datefield in the table ranges between 1st through 15th of current month.

If the current month date is the end of the month like 30 or 31st or Feb 28th then I need to pull the data from the table where the datefield in the table ranges between 16th through end of the current month.

Something like this shown below. But the code seems to be not working.

Select Case when TO_CHAR(datefield, 'YYYY-DD') = TO_CHAR(sysdate, 'YYYY') || '-' || '16' then

datefield between TRUNC(sysdate, 'MONTH') and TRUNC(sysdate, 'MONTH') + 14

when TO_CHAR(datefield, 'YYYY-DD') = TO_CHAR(sysdate, 'YYYY') || '-' || '31' then

datefield between TRUNC(sysdate, 'MONTH') + 15 and last_day(sysdate)

end

from table

Thanks

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 18 2018
Added on Dec 21 2017
7 comments
2,825 views