Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 ORDER BY FORMAT(Date, 'mmmm')

Author  Topic 

lsy
Yak Posting Veteran

57 Posts

Posted - 2005-09-08 : 22:55:36
i wonder how can i order my statement interm of "ORDER BY FORMAT(Date, 'mmmm')" with using this it will order by alphabethical but i want it order by month... i had try "ORDER BY FORMAT(Date, 'mm')" but due to at the begining i have "SELECT FORMAT(Date, 'mmmm')FROM TABLE"
my actual statement will look like this
"SELECT FORMAT(Date, 'mmmm')AS DateMonth, COUNT(x) AS CounterX FROM Table WHERE FORMAT(Date, 'mmmm') BETWEEN 'January' AND 'August' GROUP BY FORMAT(Date, 'mmmm') AND ORDER BY FORMAT(Date, 'mmmm')ASC"...

i want it order by month not alphabetical....
pls adviced... thanks in advanced.

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-09-08 : 23:27:45
use the Month function to return the numeric month value of a date.
Go to Top of Page

lsy
Yak Posting Veteran

57 Posts

Posted - 2005-09-08 : 23:59:55
i had try ORDER BY MONTH(Date)
it also doesn't work.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-09 : 02:09:40
Have you tried Order by Date?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

lsy
Yak Posting Veteran

57 Posts

Posted - 2005-09-09 : 02:37:33
yes, i been try this as well... because at the beginning i been cast the Date as FORMAT(Date, 'mmmm') so it not allow me order by other format... pls advice asap...
thanks...
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-09-09 : 09:05:58
quote:
Originally posted by lsy

i had try ORDER BY MONTH(Date)
it also doesn't work.



What didn't work? you got the wrong results? An error message? Saying "it didn't work" doesn't help us help you much ....

select Month(Date), Count(x) as CounterX
from Table
where Month(Date) between 1 and 8
group by Month(Date)
order by Month(Date)

If you want to display the month name as well, just add your existing Format() function in both the select and the group by.

Keep in mind what will happen if your data spans more than 1 year -- you will Jan-Aug for all years, all mixed together based on your existing logic. It may be much easier (and will be more efficient) to explicitly indicate the range of dates you want:

WHERE Date BETWEEN #1/1/2005# and #8/31/2005#

(for example)

Alternatively, you could do something like this:

WHERE Year(Date) = 2005
Go to Top of Page
   

- Advertisement -