SQL Concatenate Fiscal Year

I using the code below and would like to concatenate the C_COMPLETE_REQUEST_RECVD_DT in the following format;
FY YY

Output:

FY 02
FY 14
FY 14
FY 15
FY 15
FY 15
FY 15
FY 15


,Case WHEN EXTRACT(MONTH FROM C_COMPLETE_REQUEST_RECVD_DT) < 10 THEN EXTRACT(YEAR FROM C_COMPLETE_REQUEST_RECVD_DT) ELSE EXTRACT(YEAR FROM C_COMPLETE_REQUEST_RECVD_DT)+1 END AS FY

Open in new window

shieldscoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulEE Topic AdvisorCommented:
select 
      concat('FY ', CASE WHEN EXTRACT(MONTH FROM C_COMPLETE_REQUEST_RECVD_DT) < 10 
                    THEN right(EXTRACT(YEAR FROM C_COMPLETE_REQUEST_RECVD_DT) ,2)
                    ELSE right(EXTRACT(YEAR FROM C_COMPLETE_REQUEST_RECVD_DT)+1 ,2)
            END) AS FY
from your_table

Open in new window

0
shieldscoAuthor Commented:
java.sql.SQLSyntaxErrorException: ORA-00904: "RIGHT": invalid identifier
0
PortletPaulEE Topic AdvisorCommented:
OK. That's because I used a function supported by MySQL but not Oracle. You did not tell us the database was Oracle. In future please always add the database vendor to your sql related questions.

The alternative in Oracle is to use substr() and the manner of concatenation can be different as well.
select 
      'FY ' || CASE WHEN EXTRACT(MONTH FROM C_COMPLETE_REQUEST_RECVD_DT) < 10 
                    THEN substr(EXTRACT(YEAR FROM C_COMPLETE_REQUEST_RECVD_DT) ,-2)
                    ELSE substr(EXTRACT(YEAR FROM C_COMPLETE_REQUEST_RECVD_DT)+1 ,-2)
            END AS FY
from (
    select to_date('2017-09-11','yyyy-mm-dd') as C_COMPLETE_REQUEST_RECVD_DT from dual
    union all
    select to_date('2018-01-01','yyyy-mm-dd') as C_COMPLETE_REQUEST_RECVD_DT from dual
    ) d

OR

select 
      concat('FY ', CASE WHEN EXTRACT(MONTH FROM C_COMPLETE_REQUEST_RECVD_DT) < 10 
                    THEN substr(EXTRACT(YEAR FROM C_COMPLETE_REQUEST_RECVD_DT) ,-2)
                    ELSE substr(EXTRACT(YEAR FROM C_COMPLETE_REQUEST_RECVD_DT)+1 ,-2)
            END) AS FY
from (
    select to_date('2017-09-11','yyyy-mm-dd') as C_COMPLETE_REQUEST_RECVD_DT from dual
    union all
    select to_date('2018-01-01','yyyy-mm-dd') as C_COMPLETE_REQUEST_RECVD_DT from dual
    ) d

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

PortletPaulEE Topic AdvisorCommented:
actually, using to_char() is probably safer/better than using substr() as it removes a implied type conversion

select 
      'FY ' || CASE WHEN EXTRACT(MONTH FROM C_COMPLETE_REQUEST_RECVD_DT) < 10 
                    THEN to_char(C_COMPLETE_REQUEST_RECVD_DT,'rr')
                    ELSE to_char(C_COMPLETE_REQUEST_RECVD_DT,'rr')
            END AS FY
from (
    select to_date('2017-09-11','yyyy-mm-dd') as C_COMPLETE_REQUEST_RECVD_DT from dual
    union all
    select to_date('2018-01-01','yyyy-mm-dd') as C_COMPLETE_REQUEST_RECVD_DT from dual
    ) d

Open in new window

0
Bill PrewCommented:
Please try this:

'FY ' || MOD(CASE WHEN EXTRACT(MONTH FROM C_COMPLETE_REQUEST_RECVD_DT) < 10 THEN EXTRACT(YEAR FROM C_COMPLETE_REQUEST_RECVD_DT) ELSE EXTRACT(YEAR FROM C_COMPLETE_REQUEST_RECVD_DT)+1 END,100) AS FY

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awking00Information Technology SpecialistCommented:
I'm assuming you're trying to deal with a September 30th fiscal year ending. If that's the case, you might just try -
SELECT 'FY '||TO_CHAR(ADD_MONTHS(C_COMPLETE_REQUEST_RECVD_DT,3),'YY') as fiscal_year
FROM yourtable;
1
shieldscoAuthor Commented:
Thank you again Bill
0
Bill PrewCommented:
Welcome, glad that helped.


»bp
0
awking00Information Technology SpecialistCommented:
I would have thought you might have found my solution worthwhile. It seemed a lot simpler than applying multiple extract functions, a case statement, and an implicit type conversion (i.e. adding 1 to the extract of the year before the concatenation). :-(
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.