Jeff's SQL Server Blog

Random Thoughts & Cartesian Products with Microsoft SQL Server
posts - 155, comments - 2679, trackbacks - 64

My Links



Welcome to my weblog. My name is Jeff Smith, I am software developer in Boston, MA and I was recently named a 2009 SQL Server MVP. Check in frequently for tips, tricks, commentary and ideas on SQL Server and .NET programming.



Post Categories




Slightly more dynamic ORDER BY in SQL Server 2005

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

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!

Print | posted on Tuesday, June 05, 2007 10:24 AM | Filed Under [ Techniques Links ]



# 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.
6/6/2007 9:46 AM | John S.

# re: Slightly more dynamic ORDER BY in SQL Server 2005

Could one just use dynamic sql?
4/1/2010 5:33 PM | Shane
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET