Connecting Tech Pros Worldwide Help | Site Map

Sorting a query on part of a date.

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 09:04 PM
Neil Grantham
Guest
 
Posts: n/a
Default Sorting a query on part of a date.

Hi

I have a Report based on a query, whose code looks like this:
SELECT Nursery.ChildID, Nursery.[Child Forenames], Nursery.[Child
Surname], Nursery.[Child Familiar Name], Nursery.ChildDOB,
GetIntakeTerm([ChildDOB]) AS IntakeTerm
FROM Nursery
GROUP BY Nursery.ChildID, Nursery.[Child Forenames], Nursery.[Child
Surname], Nursery.[Child Familiar Name], Nursery.ChildDOB,
GetIntakeTerm([ChildDOB]);

The GetIntakeTerm is a Module that calculates which Term a child falls
in to relating to their date of Birth and looks like this:
Function GetIntakeTerm(ChildDOB) As String
Select Case Month(ChildDOB)
Case 1 To 3
GetIntakeTerm = "Spring"
Case 4 To 9
GetIntakeTerm = "Summer"
Case 10 To 12
GetIntakeTerm = "Autumn"
End Select
End Function

I would really like the report to sort on both the Year and Term, so
that it will be a year on year report of children attending a nursery
and the Term they start in.

I have looked at DatePart, but would really appreciate some
suggestions on how to modify the code to achieve my goal.

Thanks in advance
Neil

  #2  
Old November 12th, 2005, 09:04 PM
Bob Quintal
Guest
 
Posts: n/a
Default Re: Sorting a query on part of a date.

neil40@btinternet.com (Neil Grantham) wrote in
news:c66a9b10.0403311613.4cce54f@posting.google.co m:
[color=blue]
> Hi
>
> I have a Report based on a query, whose code looks like this:
> SELECT Nursery.ChildID, Nursery.[Child Forenames],
> Nursery.[Child Surname], Nursery.[Child Familiar Name],
> Nursery.ChildDOB, GetIntakeTerm([ChildDOB]) AS IntakeTerm
> FROM Nursery
> GROUP BY Nursery.ChildID, Nursery.[Child Forenames],
> Nursery.[Child Surname], Nursery.[Child Familiar Name],
> Nursery.ChildDOB, GetIntakeTerm([ChildDOB]);
>
> The GetIntakeTerm is a Module that calculates which Term a
> child falls in to relating to their date of Birth and looks
> like this: Function GetIntakeTerm(ChildDOB) As String
> Select Case Month(ChildDOB)
> Case 1 To 3
> GetIntakeTerm = "Spring"
> Case 4 To 9
> GetIntakeTerm = "Summer"
> Case 10 To 12
> GetIntakeTerm = "Autumn"
> End Select
> End Function
>
> I would really like the report to sort on both the Year and
> Term, so that it will be a year on year report of children
> attending a nursery and the Term they start in.
>
> I have looked at DatePart, but would really appreciate some
> suggestions on how to modify the code to achieve my goal.
>
> Thanks in advance
> Neil
>[/color]
Remove the group by stuff from the query. Open your report in
design mode. click on the "sorting and grouping" icon in the
toolbar. Enter the fields you want ot group and sort by.

Save the report and test.

Bob Q





 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.