CASE Statement for Order By Clause with Multiple Columns and Desc/Asc Sort

前端 未结 2 1675
-上瘾入骨i
-上瘾入骨i 2021-02-01 18:01

Following on from my earlier question here Case statement for Order By clause with Desc/Asc sort I have a statement like this:

SELECT 
    *
FROM
    TableName
W         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 18:57

    Do you need this?

    ORDER BY
        CASE @OrderByColumn WHEN 1 THEN Forename END DESC, Date, Location,
        CASE @OrderByColumn WHEN 2 THEN Surname END ASC 
    

提交回复
热议问题