Yogesh Jindal Yogesh Jindal - 1 year ago 70
SQL Question

orderby in sql query

I need to order sql query by a column (the three different values in this column are C,E,T).

I want the results in order of E,C,T. So, of course I can't use ascending or descending orderby on this column.

Any suggestions how can I do this? I don't know if that matters or not but I am using sybase data server on tomcat.

Answer Source

The other methods work, but this is an often overlooked trick (in MSSQL, I'm not positive if it works in Sybase or not):

order by
  case foo 
    when 'E' then 1
    when 'C' then 2 
    when 'T' then 3 
    else 4