Jeff Smith Blog

Random Thoughts & Cartesian Products with Microsoft SQL Server

Slightly more dynamic ORDER BY in SQL Server 2005

There's a very interesting way of handling complicated, multi-column dynamic sorts over at john-sheenan.com.

I am not sure about the efficiency of this approach, but in general dynamic sorting tends not to be very efficient anyway (unless you use dynamically-created SQL statements).  Overall, it is a very clever use of RANK() and definitely worth a look.

Thanks for the great idea, John!

Legacy Comments


John S.
2007-06-06
re: Slightly more dynamic ORDER BY in SQL Server 2005
Hey Jeff, thanks for the link. I originally developed this method for use with pretty small result sets (<100 rows) and I haven't had an performance issues. I haven't done any testing with bigger sets, but I'm pretty sure it won't scale. I'm not good enough with perf testing though to run any comparison tests.

Shane
2010-04-01
re: Slightly more dynamic ORDER BY in SQL Server 2005
Could one just use dynamic sql?