Solved

Fiscal Year Date Query

Posted on 2006-07-10
4
1,945 Views
Last Modified: 2011-10-03
I need to run a query against a date field in Oracle 9i which determines whether the date within the current Fiscal Year.  (Oct-Sept).

How would I do that?  What's the eaisiest, portable way?
0
Comment
Question by:lcor
  • 2
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 17075092
date functions are not portable as of today. every database has it's own function names.

so, to be portable, you have only 1 solution:
 create a table with 3 (4) columns

* start_date
* end_date
* fiscal_year_display
* key_field

I guess the rest should be obvious, apart from the decision how to fill this table (I use 100 years and supply a button in the application that allows to add/edit rows for the future
0
 
LVL 14

Assisted Solution

by:sathyagiri
sathyagiri earned 150 total points
ID: 17075127
0
 
LVL 44

Assisted Solution

by:Arthur_Wood
Arthur_Wood earned 150 total points
ID: 17075528
here is a 'trick' which will return the correct fiscal year, without the need to add a new table to do the conversion.

what you want to do is to ADD 3 months to the actual date, and then take the Year of the result (the three months will effectively advancce OCTOBER of the current year to JANUARY of the FOLLOWING year, and the YEAR function will then return the 'correct Fiscal Year', as the Year to which the follong January belongs).  You do this only to get the Fiscal Year of the data, not to actually modify the dates in any way.

Select <Date_Field>,TO_CHAR(Add_Months(<DATE_Field>, 3), 'YYYY') as Fiscal_Year from YourTable

Change <Date_Field> to the name of the Date field in your table.

AW
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17075586
AW: your trick is not portable :-)
to_char, add_months do not exist in SQL Server and MySQL (to name only these)...
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now