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

MS Access query date sorting question

Posted on 2016-11-17
Last Modified: 2016-11-17
I have a simple query and I can't figure out how to first sort the data by year then by month
Question by:cssc1
  • 3
  • 3
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41892070
try this

SELECT tblContact.ContactID, tblGoodCatch.GoodCatchNo, tblContact.LastName, tblContact.FirstName, tblContact.JobTitle, tblContact.Foreman, tblContact.Shift, tblGoodCatch.GoodCatchDescription, tblGoodCatch.GoodCatchMonthlyWinner, tblContact.Terminated, tblGoodCatch.GoodCatch_NearMiss, tblGoodCatch.Date_, tblGoodCatch.Month___, tblGoodCatch.Year__, tblGoodCatch.SubmittedGC, tblGoodCatch.SubmittedNM
FROM tblContact INNER JOIN tblGoodCatch ON tblContact.ContactID = tblGoodCatch.GoodCatchNo
ORDER BY tblGoodCatch.Year__, tblGoodCatch.Date_;
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41892072
if you want to sort by Year, Month, use this

ORDER BY tblGoodCatch.Year__, tblGoodCatch.Month___

Author Comment

ID: 41892124
Sorry, but where do I put this code that you have provided?
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

LVL 120

Accepted Solution

Rey Obrero (Capricorn1) earned 500 total points
ID: 41892128
here see query_Year_Date, query_Year_Month

Author Comment

ID: 41892161
Work fine, thanks!
LVL 35

Expert Comment

ID: 41892162
Notice that Month__ was added a second time to the grid but the show box is unchecked.  If you rearrange the grid to have year to the left of month, you don't need to repeat the month field.qrySort.JPG
Rather than using some number of underscores as a suffix, why not use a meaningful prefix to avoid conflict with reserved words?

CatchDate, CatchMonth, CatchYear.

Also, why are year and month separate from date?  Given their data content they don't seem to have any relationship to CatchDate so perhaps some prefix other than "Catch" makes more sense.

Author Closing Comment

ID: 41892163
Works fine, thanks!

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

792 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