I’m trying to figure out how to involve NEWID() (so I can return the results in a random order) in a CASE statement with in the ORDER BY clause, like so:
ORDER BY CASE WHEN @RankingMethod = 1 THEN intFoo ELSE NEWID() END DESC
Obviously this doesn’t work, as it throws “Operand type clash: uniqueidentifier is incompatible with int”
Is there a way to construct this ORDER BY to have it either sort randomly or by a specified column?
You could do
If needed, choose another “magic value” instead of
-1