it is ordering by the converted value (which is no longer a date).try this:select convert(char(10), hire_date, 105) hire_dateStr, cntfrom (select hire_date, count(*) cnt from employee group by hire_date) aorder by hire_date
EDIT:I guess mine only works because there is only 1 row per hire date day anyway. But you get the idea.You should try to avoid doing conversion from and to dates if you can help it. Use the front end app to format the date.Here is an alternative to group by days without the conversions. Return this and format it as desired in the presentation layerselect dateadd(day, datediff(day,0,hire_date),0), count(*) cntfrom employeegroup by dateadd(day, datediff(day,0,hire_date),0)order by 1
Be One with the OptimizerTG