SELECT is an SQL keyword. SQL is the language in which queries are written.
If you design a query in the query designer in Access the SQL code is created
for you. You can see it by switching to SQL view. To sort by date within
each month, regardless of year, one way is to sort on the return value of the
MONTH function. If you then have a second sort level on the date itself the
rows will be sorted by month, then each group of rows in the same month,
regardless of year, will be in actual date order:
SELECT *
FROM MyTable
ORDER BY MONTH(MyDate), MyDate;
As you want to sort in a report, however, its pointless doing it in the
query. Instead you should do it in the report via the sorting and grouping
dialogue in report design view. To do this you can base the report on a
query which includes a computed column to return the month values from each
date:
SELECT *, MONTH(MyDate) As SortByMe
FROM MyTable;
To do this in query design view rather than SQL, design the query in the
usual way, then in the 'field' row of a blank column in the query design grid
put:
SortByMe:MONTH([MyDate])
substituting the real name of your date field of course. Make sure the
'Show' checkbox is checked.
In a report with this query as its RecordSource open the sorting and
grouping dialogue in design view, either from the toolbar or the View|Sorting
and Grouping menu item. Select SortByMe as the first sort level and MyDate
as the second.
BTW the format of a date/time column in datasheet view of your table is
immaterial. Date/Time values are actually stored as a 64 bit floating point
number as an offset from midnight on 30 December 1899, the integer part of
the number representing days, the fractional part the time of day. The
format is just how you see them. Here I use the UK format of dd/mm/yyyy, but
the above would still work as the actual values of the dates are the same
regardless of the format employed.
Sanford said:
Thank you for your reply Ken.
The column is formatted mm/dd/yyyy in calendar format. 'Sort by month' means
that I can create a report where any month's dates are sorted by date value
regardless of year.
But what does your response mean??