I saw some topics about this, but the problem is that the solutions required a “switch case”… Like this
I have a table with a lot of columns, is there a way to do a dynamic sort without the switch?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No.
Unless you use dynamic SQL.
Or you can use ROW_NUMBER() to generate some arbitrary sequences to sort on… but this is no different to CASE just moves the complexity around.
To be honest, if I had one of 10 columns to sort on, I’d make it happen on the client in a sortable grid…