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

syed haiderSep 27 2018 — edited Sep 28 2018

I have a case statement displaying all 4 quarters. I also want to display current year as cy, but the case statement is ignoring the current year

select 
        case when trunc(date_gra_created) between q1_begin_date and q1_end_date then 'Q1'
             when trunc(date_gra_created) between q2_begin_date and q2_end_date then 'Q2'
             when trunc(date_gra_created) between q3_begin_date and q3_end_date then 'Q3'
             when trunc(date_gra_created) between q4_begin_date and q4_end_date then 'Q4'
             when trunc(date_gra_created) between q1_begin_date and report_end_date then 'ytd'
        end dates
from rpt_quarter qr   

ouptut

Q1

Q2

Q3

Q4

Whereas, I want the output to be

Q1

Q2

Q3

Q4

YTD

I know the reason is because YTD is overlapping with Q1 to Q4 and since it's the last item, case statement doesn't choose it.

What could I do to show YTD. I tried union all, but that's taking a long time for my report to run. Is there any other method that I could apply. Thanks in advance!

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 26 2018
Added on Sep 27 2018
29 comments
1,637 views