?
Solved

Sort Fiscal Months Desc by Name

Posted on 2008-09-29
5
Medium Priority
?
684 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

How to increase the row limit in Jasper Server.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

764 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