接下来是我前面的问题,在此以Desc / Asc排序的Order By子句的案例陈述是这样的:
SELECT * FROM TableName WHERE ORDER BY CASE @OrderByColumn WHEN 1 THEN Forename END DESC, CASE @OrderByColumn WHEN 2 THEN Surname END ASC
这很好用,但是有时候我需要的不仅仅是按顺序排列的列。我实际上需要这样的东西:
..... ORDER BY CASE @OrderByColumn WHEN 1 THEN Forename, Date, Location END DESC
我无法弄清楚如何使该CASE语句在THEN零件中允许多列。
CASE
THEN
你需要这个吗?
ORDER BY CASE @OrderByColumn WHEN 1 THEN Forename END DESC, Date, Location, CASE @OrderByColumn WHEN 2 THEN Surname END ASC