• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 59
  • Last Modified:

MS Access query date sorting question

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
cssc1
Asked:
cssc1
  • 3
  • 3
1 Solution
 
Rey Obrero (Capricorn1)Commented:
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
 
Rey Obrero (Capricorn1)Commented:
if you want to sort by Year, Month, use this

ORDER BY tblGoodCatch.Year__, tblGoodCatch.Month___
0
 
cssc1Author Commented:
Sorry, but where do I put this code that you have provided?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Rey Obrero (Capricorn1)Commented:
here see query_Year_Date, query_Year_Month
TEST_DB_rev.accdb
0
 
cssc1Author Commented:
Work fine, thanks!
0
 
PatHartmanCommented:
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
 
cssc1Author Commented:
Works fine, thanks!
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

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