I am using SQL Server 2008 working on an existing query that does not sort columns correctly. The columns indicate years of service. Column headers are, and should be in the following order: ![alt text] They keep coming in in numerical order by the first number: ![alt text] These columns come from a case statement which uses the hire date. Then a count is done on the employee_ID by years of service. The column headers used to begin with a), b), c), d), e), f) but the user has been deleting these and asked that they be deleted from the report. I now believe the a,b,c, etc. was used for sorting. Does anyone know how I can force the columns into the order I need them to be in? Thank you very much! P.S. GROUP BY: the case statement, hire date, job title, and employee id. ORDER BY: the case statement, job title, and hire date : /storage/temp/735-yos.png : /storage/temp/736-yos+wrong.png
If you've deleted that A, B, C etc, then one thing you could do is add in an ORDER BY statement like this: ORDER BY CASE ColumnHeader WHEN '0-1' THEN 0 WHEN '1-2' THEN 1 WHEN '2-5' THEN 2 WHEN '5-10' THEN 3 WHEN '10-15' THEN 4 WHEN '15+' THEN 5 END You mention also the "hire date" - is that in your outermost SELECT statement? If so, then you can sort on that, even if you're not selecting it.