sam15
asked on
FiscalYearDateQuerrySQL
I have a stock item table like this
stock_item
-----------
stock_code varchar2(10)
discontinued varchar2(1)
date_discontined date
I want to report on items that are not disconitnued or that have been discontinued this fiscal year only. I want to exclude any items discontinued previous fiscal year or before.
Disconitnued = 'Y'
Not discontinued = NULL
What is the best sql for that. I was thinking of somethig like this
select stock_code from stock_item where discontinued IS NULL OR (discontinued='Y' and date_discontinued >= '01-OCT-'||to_char(to_char (trunc(sys date('YYYY '))-1)
since there is no function that subtracts 3 months from 1st day of year.
ADD_MONTHS only adds months.
stock_item
-----------
stock_code varchar2(10)
discontinued varchar2(1)
date_discontined date
I want to report on items that are not disconitnued or that have been discontinued this fiscal year only. I want to exclude any items discontinued previous fiscal year or before.
Disconitnued = 'Y'
Not discontinued = NULL
What is the best sql for that. I was thinking of somethig like this
select stock_code from stock_item where discontinued IS NULL OR (discontinued='Y' and date_discontinued >= '01-OCT-'||to_char(to_char
since there is no function that subtracts 3 months from 1st day of year.
ADD_MONTHS only adds months.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
don't need to_char at all, but if you were going to do that (and I don't recommend it)
it would look something like
to_date( '01-OCT-'||(to_char(sysdat e,'yyyy')- 1),'dd-MON -yyyy')
or more formally
to_date( '01-OCT-'||to_char((to_num ber(to_cha r(sysdate, 'yyyy'))-1 )),'dd-MON -yyyy')
it would look something like
to_date( '01-OCT-'||(to_char(sysdat
or more formally
to_date( '01-OCT-'||to_char((to_num
ASKER
you are a genius!