I have this MS-SQL query with thousands of row records in database:
SELECT DISTINCT TOP 7 DATENAME(MM, mydatetime) + \' \' + CAST(DAY(mydatetime) AS VA
To get the order you specify including only the dates you want in the return results you need to remove the desc and add a date filter to your where clause.
That may also allow you to get rid of the top statement if your do your filter right.
SELECT DISTINCT TOP 7 DATENAME(MM, mydatetime)
+ ' ' + CAST(DAY(mydatetime) AS VARCHAR(2)) as thedate
, MONTH(mydatetime)
, DAY(mydatetime)
, COUNT(Page) as totalcount
, count(DISTINCT Page) as visitors
FROM someTable
WHERE Page LIKE '%AEC%'
AND /* filter date range i.e. MONTH(mydatetime) > 9 AND YEAR(mydatetime) > 2011 */
GROUP BY DATENAME(MM, mydatetime) + ' ' + CAST(DAY(mydatetime) AS VARCHAR(2))
, MONTH(mydatetime)
, DAY(mydatetime)
ORDER BY MONTH(mydatetime)
, DAY(mydatetime)