Try it like this:
SELECT ... ORDER BY CASE WHEN @OrderBy = 'Option1' THEN SomeField END, CASE WHEN @OrderBy = 'Option1' THEN SomeOtherField END DESC, CASE WHEN @OrderBy = 'Option2' THEN Field75 END, ...
The idea is that each CASE statement will evaluate to NULL if WHEN it does not match. Therefore, if you set Option2, you will get a constant value for the first two parameters.
Thus, using this, you can easily have some options that allow you to sort by multiple fields, or descending, or whatever you want.
Rob
source share