Best of the forums
I hope everyone is enjoying the SQLTeam blogs so far. Graz, Rob and I have been talking about this idea for a little while, well.. we knew we wanted to do something, but weren't totally sure of the format. One of the things I wanted to do was to have a way to highlight some of the really cool solutions that get posted every day in our forums. Because of the nature of forum software, once a question is answered it slowly drops down the list until they aren't visible any more. So I wanted a way to bring out the best ones in a slightly more permanent manner. Allow me to present the first (of what hopefully will be many) posts under the heading Best of the forums.
Today's forum thread is a few months old now, I've had it set aside waiting for this. It involves dynamic sort orders in a query. We have a great article on SQLTeam about this, but one of the limitations of this method is the fact that the columns you want to sort by have to be the same data type. If you read the comments to this article, you find out that the most common way to work around this is using multiple sort columns.
DavidM posted a great answer to this problem here in this thread. As soon as I read it I slapped my head and went "DUH". It was so simple, yet never crossed my mind before. Read, learn and enjoy!
This is also going to go up on the main SQLTeam page, if anybody sees something in the forums that you would like to see highlighted, drop me a line and I'll take a look.
Legacy Comments
Jeff
2003-10-05 |
re: Best of the forums be careful with the varbinary trick -- it doesn't work for decimal types, and it also makes varchar's case sensitive. For example: declare @t table (c varchar(10), d decimal(9,4)) insert into @t select 'Jeff', 2 union select 'bill', .22 union select 'Pete', 2.22 select * from @t order by convert(varbinary(50), d) select * from @t order by convert(varbinary(50), c) |