Sorting Months

N

Neil Greenough

I have created a table which contains the months of the year. I have a link
from another table to this one. Nonetheless, the table containg the months
has automatically sorted the table ascending, and so it starts with April as
opposed to January.

Anybody know how I can change this?
 
T

Tom Wickerath

You can use the Month function applied to a Date/Time field in a query and sort ascending by this
number. For example, the following query in the sample Northwind database will display all orders
placed in the month of January, before any orders placed in February, which are listed before any
orders placed in March, etc.

SELECT CompanyName, OrderDate
FROM Customers INNER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
ORDER BY Month([OrderDate]), Orders.OrderDate;

I have created a table which contains the months of the year.
Are you saying that this is text field that is populated with values such as "January",
"February", "March", (or "Jan", "Feb", "Mar"), etc? If so, I don't think that you need this
table. You can always return a string indicating the specified month by using the MonthName
function. For example:

SELECT CompanyName, OrderDate,
MonthName(Month([OrderDate])) AS [Month Ordered]
FROM Customers
INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Month([OrderDate]), OrderDate;

or, to see just the three-letter abbreviation for each month, set the optional abbreviate value
to TRUE:

SELECT CompanyName, OrderDate,
MonthName(Month([OrderDate]),TRUE) AS [Month Ordered]
FROM Customers
INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Month([OrderDate]), OrderDate;


Tom
_______________________________________


I have created a table which contains the months of the year. I have a link
from another table to this one. Nonetheless, the table containg the months
has automatically sorted the table ascending, and so it starts with April as
opposed to January.

Anybody know how I can change this?
 
B

BerHav

Hi Neil,

Which field type did you choose for the months? Text or Date?

Probably it would help to add a second column with the numbers 1 to 12 and a
'sort' on this column.

Cheers,
Bernd
 
Top