SELECT *
FROM
TableName
WHERE
ORDER BY
CASE @OrderByColumn
WHEN 1 THEN Forename
WHEN 2 THEN Surname
END;
I have a statement like above which lets me dynamically choose how to order the results of a query. However, how do I specify that I want the Forename ordered DESC
and the Surname ASC
?
another example:
more details ...http://codechef4u.com/post/2015/04/07/order-by-clause-with-case-expressions-case-statement
You need to split your
ORDER BY
in two parts:You need two clauses in the
order by
: