[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1681
  • Last Modified:

Access: Sorting Months in a query in the correct order

I have a query that sorts out months in the following format:

Field:              Month                
Row1         August 2006                        
Row2         September 2006            
Row3         October 2006                  
Row4         November 2006              
Row5         December 2006
Row6         January 2007
Row7         February 2007
Row8         March 2007
Row9         April 2007
Row10         May 2007
Row11         June 2007
Row12         July 2007
Row13         August 2007

The problem is that sometimes (Unlike above) the months are in the wrong order. How do I sort the month column to insure that the month and year are always in the correct order (As above)            
0
ouestque
Asked:
ouestque
  • 4
  • 3
  • 3
  • +3
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what is the actual input field? is it datetime, or is it already a string in that format.
0
 
Emil_GrayCommented:
If you are using a query then it is easy. Create a new field just for sorting purposes. Format your original date field there as follows:

Format([mydate], "yyyymmdd")
0
 
Rey Obrero (Capricorn1)Commented:
select * from NameofTable
order by format([Month],"yyyymm)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jerryb30Commented:
If text, Order By datevalue(MonthAndYear)
0
 
Emil_GrayCommented:
As I said initially since I presume you are using a query create a new field in the query. I'll call it myDate for the purpose of explaining.

Format the field as a Date/Time field. In the query the field would look like myDate: Format([MonthYear], "yyyymmdd") where [MonthYear] is the name of your field in the query that holds the data you are trying to sort. Then you sort the myDate field as you wish.
0
 
jerryb30Commented:
If it is a date field, it will order regardless of how you format.  
If it is a text field, you will not get format to handle it anyway.
0
 
Rey Obrero (Capricorn1)Commented:
<If it is a text field, you will not get format to handle it anyway.>

why not try my post.

  select * from NameofTable
order by format([Month],"yyyymm)
0
 
Rey Obrero (Capricorn1)Commented:
?format("january 2007","yyyymm")  will give you

200701
0
 
jerryb30Commented:
I am amazed. I bow to your superior intellect. Yet again.
0
 
Emil_GrayCommented:
capricorn1 and jerryb30, if the field showing the Month and Year that the questioner provided is a Date/Time field then the solution I first proposed is the easiest answer. This is not rocket science.

Format a new field as a Date/Time field. In your query the field would look like;

myDate: Format([MonthYear], "yyyymmdd")

where [MonthYear] is the name of your field in the query that holds the data you are trying to sort. Then you sort the myDate field as you wish either Ascending or Descending.
0
 
ouestqueAuthor Commented:
Thank ya'll so much!!! I really appreciate you help. Emil_Gray posted the correct answer first and therefore she gets the points. Thanks!!!
0
 
Emil_GrayCommented:
ouestque, thank you. However I am a male not a female.

Emil Gray
0
 
cspbarnesCommented:
And if you looking to only do it for the month, let's say a Birthday list, then you would use
myDate: Format([Month], "mm")
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 4
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now