Solved

Sort Fiscal Months Desc by Name

Posted on 2008-09-29
5
635 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

770 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