Case statement for Order By clause with Desc/Asc sort

后端 未结 3 985
感情败类
感情败类 2021-02-14 16:07
SELECT *
FROM
    TableName
WHERE
ORDER BY 
    CASE @OrderByColumn
    WHEN 1 THEN Forename
    WHEN 2 THEN Surname
    END;

I have a statement like a

3条回答
  •  野的像风
    2021-02-14 16:46

    another example:

    SELECT * FROM dbo.Employee
    ORDER BY 
     CASE WHEN Gender='Male' THEN EmployeeName END Desc,
     CASE WHEN Gender='Female' THEN Country END ASC
    

    more details ...http://codechef4u.com/post/2015/04/07/order-by-clause-with-case-expressions-case-statement

提交回复
热议问题