I am trying to use the following function that counts the number of orders by hour:
SELECT
COUNT(id) total,
DATENAME(HOUR, purchased_on) label,
site
FROM dhs.dbo.orders
WHERE purchased_on >= '01/16/2013'
GROUP BY DATENAME(HOUR, purchased_on), site
ORDER BY label DESC
I am getting the following results even though I am using and ORDER BY clause that should put them in order from the highest label to the lowest:
total label site
2 9 AMAZON
1 9 DHS
2 8 AMAZON
1 7 AMAZON
1 6 AMAZON
1 4 AMAZON
1 12 AMAZON
3 11 AMAZON
1 10 AMAZON
1 10 DHS
Why doesn’t the order by work?
DATENAMEreturns aVARCHAR.Replace it with
DATEPART: