Solved

SQL - how to order a query result set by year and month

Posted on 2014-07-31
2
580 Views
Last Modified: 2014-07-31
Good Afternoon Experts,

I have a table that houses data over the period of 5 years.  The fields are
year
monthname
monthnumber
group
secondgroup
section
numbers

Problem:  I need to get a query result that will order the resultset by year then month.  So, in the best of all possible worlds, the result set would be ordered by
2010 jan
2010 feb
2010 Mar
and so on
2011 Jan
2011 Feb
2011 Mar
and so on
2012 Jan
2012 Feb
2012Mar
and so on

Is this possible?

Thank you !
0
Comment
Question by:UserName935
2 Comments
 
LVL 36

Accepted Solution

by:
PatHartman earned 250 total points
ID: 40232042
Order by year and monthnumber.

If Year is actually the name of the column, change it if you can.  You should not use the names of functions, methods, or properties - or any other reserved words as column names in tables.

Short of memorizing long lists of reserved words, the best technique is to use compound names
RptYear, ProjSection.
0
 
LVL 21

Assisted Solution

by:Randy Poole
Randy Poole earned 250 total points
ID: 40232046
Select * from yourtable order by [year],[monthnumber]
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

713 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