Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Oracle SQL help - Financial Year 1

Status
Not open for further replies.
Nov 5, 2001
339
GB
Hi All,

I am trying to get an SQL WHERE clause to select records for the current finacial year only. Therefore it needs to take the 'sysdate' and, depending on the month, create a query against a date of either

A) my_date >= 01/04/YYYY and my_date <= 31/03/YYYY+1

OR

B) my_date >= 01/04/YYYY-1 and my_date <= 31/03/YYYY

I'm using UK 'DD/MM/YYYY' date formats and case A above should be used if the current month is >= 4, otherwise case B should be used. YYYY is, of course, the sysdate year value.

I hope this makes sense. I have tried various things but am not great at Oracle SQL I'm afraid. Any help would be much appreciated.

Steve Phillips, Crystal Trainer/Consultant
 
Hi Steve,

a lot of solutions should be possible, I think.
One of them:

... where trunc(my_date) between
add_months(trunc(add_months(sysdate,-3),'y'),3)
and
add_months(trunc(add_months(sysdate,-3),'y'),15)

regards
 
Hi Steve,

sorry, it seems my solution is not quite correct;
it will include 1st of April 2006 in the current fiscal year.
[sad]
Don't trust anybody who seems to give elegant solutions[wink]

better should be:
... where trunc(my_date) >= add_months(trunc(add_months(sysdate,-3),'y'),3)
and trunc (my_date) < add_months(trunc(add_months(sysdate,-3),'y'),15)

 
I was going to do some testing on the last date in the range as I wasn't sure it was going to work - looks like you've saved me some more time!

(I can't give you another star though!)

Thanks again

Steve Phillips, Crystal Trainer/Consultant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top