Order by not functioning properly?

  • In the last case you are ordering by the "numbers" 1 and 2, 2 and 1, or 2 and 1.  These numbers are not aliases to columns, just values.  For example

    ORDER BY CASE...THEN X1 * X1 / 2 END

    X1 * X1 / 2 gets evaluated and treated as a value.  The value does not become an alias to a column. 

    To use the 1, 2, etc for columns

    ORDER BY 1, 2

    or

    ORDER BY 2, 1

    To use the above in your case, a logical IF can be use to write a query for each sort order required.  This would be better if you want the best performance.  Another option, a last resort, is ad hoc using EXEC. 

     

    Randy
    Helpdesk: Perhaps Im not the only one that does not know what you are doing. 😉

Viewing post 16 (of 15 total)

You must be logged in to reply to this topic. Login to reply