Months in Order

I run this:
SELECT     count(open_time)as Count,DATENAME(mm, open_time)AS Month
FROM       probsummarym1
WHERE (datediff (mm, getdate ( ) ,Open_Time) > -4)
GROUP BY   DATENAME(mm, open_time)

My return is this:
Count           Month
7498      May
7069      June
3855      July
6676      April
How can I run the month column to be in order.  April, May, June, July
rhservanAsked:
Who is Participating?
 
dbeneitCommented:
SELECT     count(open_time)as Count,DATENAME(mm, open_time)AS Month
FROM       probsummarym1
WHERE (datediff (mm, getdate ( ) ,Open_Time) > -4)
GROUP BY   month(open_time),DATENAME(mm, open_time)AS Month
order by  month(open_time),DATENAME(mm, open_time)AS Month
0
 
Patrick MatthewsCommented:
SELECT     count(open_time)as Count,DATENAME(mm, open_time)AS Month
FROM       probsummarym1
WHERE (datediff (mm, getdate ( ) ,Open_Time) > -4)
GROUP BY   DATENAME(mm, open_time)
ORDER BY CONVERT(datetime, DATENAME(mm, open_time) + ' 1, 2001')
0
 
dqmqCommented:
SELECT     count(open_time)as Count,DATENAME(mm, open_time)AS Month
FROM       probsummarym1
WHERE (datediff (mm, getdate ( ) ,Open_Time) > -4)
GROUP BY   DATENAME(mm, open_time)
ORDER BY Month(open_time)
0
 
rhservanAuthor Commented:
dbeneit - CORRECT - After removing the AS Month at the end of GROUP BY & order by it worked the first time.

matthewspatrick - ERROR - Line 5: Incorrect syntax near '1,2001'
dgmmg - ERROR - Column name 'open_time' is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.
Thank you all for your efforts.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.