• I really liked the subject matter of the question - mixing data types in an ORDER BY is an error I see being made lots of times, and it's not always easy to pinpoint - especially when the data used in test just happens to never cause problems (it happens! trust me)

    What I disliked was the weak obfuscation attempt. The question would have been much better with

    WHEN @sortby = 'String1' THEN String1

    WHEN @sortby = 'String2' THEN String2

    WHEN @sortby = 'Date1' THEN Date1

    Now, people may get it wrong because they were led astray by the weird reversal of column names. I don't buy the argument by the question author that this would have been "too simple" - if that really were the case (which I don't believe), the question should not have been submitted at all. In my opinion, QotD is about testing -and, even more important, gaining- SQL skills. Not reading skills. Without the reversal, the question would have been a solid test of whether people know about the dangers of using CASE in ORDER BY, and thus an excellent question. With the reversal, it's still a good question - good, not excellent.

    That being said, I do hope to see more questions from Mister Magoo in the future.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/