Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-07-31
2
Medium Priority
?
633 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 40

Accepted Solution

by:
PatHartman earned 1000 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 1000 total points
ID: 40232046
Select * from yourtable order by [year],[monthnumber]
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

824 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