Solved

Sort Fiscal Months Desc by Name

Posted on 2008-09-29
5
643 Views
Last Modified: 2010-04-21
Hi -

I am trying to sort a report by fiscal month desc. Since our fiscal year begins in July and ends in June, the latest month for a year would be June sorted through July:

June
May
April
March

Or for the current date/year
September
August
July

I have found a way to do this whenever I have a fiscal month number or week number to work with, but for this particular table all I have is a fiscal month name, so sorting results in an alphabetical sort which I do not want. Is there a way to select the fiscal month as is by name, but select again to convert to a number so that I can sort it by the latest to the earliest? Or do I just have to add something behind the scenes (I prefer not to change the table) and like a case statement, and sort by a number assigned?

Thanks -
SD
0
Comment
Question by:savetheday
  • 3
5 Comments
 
LVL 5

Expert Comment

by:NutrientMS
ID: 22600390
As far as I am aware sorting on a Month name will only do it alphabetically.  What I would do if you are able to modify the table is to add a colum for month number.  Where Month Date = January, month number = 1 etc... Then order it by Month Number.

I'm not sure if there is a way to incorporate something similar into your query.
0
 
LVL 5

Accepted Solution

by:
adlink_la earned 50 total points
ID: 22600539
Create a Date Dimension table.  Take a look at the table structure in the following article.  Im not saying you need a table with all of that stuff in it.  But if you use the same concept and create a table that has a row for every date and columns like FiscalMonthNumber, FiscalMonthName, FiscalQuarter, FiscalYear, etc., then you can increment the FiscalYear in July and set all of the other columns appropriately.  (One thing regarding the table structure in the article  I wouldnt use Date as a column name because it is a reserved word, maybe CalendarDate or whatever).

http://it.toolbox.com/wiki/index.php/Create_a_Time_Dimension_/_Date_Table


Using this table, you could sort dates for the year by doing something like:

SELECT CalendarDate
FROM Dates
WHERE FiscalYear = 2008
ORDER BY CalendarDate

Or you could join to your table with month names like:

SELECT d.CalendarDate, &
FROM Dates d
JOIN myTable a ON a.FiscalMonthName = d.FiscalMonthName
ORDER BY d.CalendarDate
0
 
LVL 5

Expert Comment

by:adlink_la
ID: 22600632
BTW, FiscalMonthName may not necessarily be the same as CalendarMonthName if the fiscal month does not start on the first of the month.  For example if the month always starts on the first Thursday or if there is some other obscure business rule, that is very easy to handle in a table.
0
 

Author Closing Comment

by:savetheday
ID: 31501341
Yes - joined the table on the other table to get the fiscal month number. Query runs slower but it works! Thanks!
SD
0
 
LVL 5

Expert Comment

by:adlink_la
ID: 22602084
You can probably speed it up by putting an index on the column you are joining on.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to increase the row limit in Jasper Server.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

860 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