Skip to Main Content

Oracle Database Discussions

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!

Help with CASE statement using dates in Oracle sql

2632048Apr 9 2015 — edited Apr 9 2015

Hello,

I need help with CASE statement that refers to a date column. I am using the following CASE statement to generate output column Number_of_days which based on the received_timstm column shows all the ID's which have no entry in either past 5/10/15/ More than 15 days.

select distinct ID, to_timestamp(RECEIVED_TIMSTM),

            case

             when trunc(sysdate) -trunc(received_timstm)   >= 5 and    trunc(sysdate) -trunc(received_timstm)   <=10  THEN '10_days'

             when trunc(sysdate) -trunc(received_timstm)   >= 10 and    trunc(sysdate) -trunc(received_timstm)   <=15  THEN '15_days'

             when trunc(sysdate) -trunc(received_timstm)   > 15  THEN 'More_15_days'

             ELSE NULL END AS  Number_of_days

from  table_name;

However, this does not seem to work.

Any help is appreciated.

Thank you so much!

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 7 2015
Added on Apr 9 2015
4 comments
1,500 views