Dynamic ORDER BY in SQL Server
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 dyna开发者_如何学运维mic sort without the switch?
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...
精彩评论