Solved

MS Access query date sorting question

Posted on 2016-11-17
7
45 Views
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
TEST_DB.accdb
Sort.png
0
Comment
Question by:cssc1
[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
  • 3
7 Comments
 
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_;
0
 
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___
0
 

Author Comment

by:cssc1
ID: 41892124
Sorry, but where do I put this code that you have provided?
0
Industry Leaders: 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!

 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 41892128
here see query_Year_Date, query_Year_Month
TEST_DB_rev.accdb
0
 

Author Comment

by:cssc1
ID: 41892161
Work fine, thanks!
0
 
LVL 37

Expert Comment

by:PatHartman
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.
0
 

Author Closing Comment

by:cssc1
ID: 41892163
Works fine, thanks!
0

Featured Post

Technology Partners: 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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

687 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