开发者

Dynamic ORDER BY in SQL Server

开发者 https://www.devze.com 2022-12-30 16:29 出处:网络
I saw some topics about this, but the problem is that the solutions required a \"switch case\"... Like this

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...

0

精彩评论

暂无评论...
验证码 换一张
取 消