案例如何运作我可以看到所有条件都经过验证并根据所有真实条件进行排序,在第一场比赛中是否存在???
ROW_NUMBER() OVER (ORDER BY
CASE WHEN @SortColumn = N'DataUsage' AND @SortAsc = 0 THEN t.DataUsage END DESC,
CASE WHEN @SortColumn = N'OSVersion' AND @SortAsc = 1 THEN t.OSMajorVersion END DESC ,
case WHEN @SortColumn = N'OSVersion' AND @SortAsc = 1 THEN t.OSMinorVersion END DESC,
case WHEN @SortColumn = N'OSVersion' AND @SortAsc = 1 THEN t.OSBuildNumber END DESC
) myRow
问题在于N'OSVersion'
答案 0 :(得分:0)
您有四种不同的case
语句。所以每个人都被执行了。
很难说你真正想要的是什么,但也许你想将它们合并为1?
(CASE WHEN @SortColumn = N'DataUsage' AND @SortAsc = 0 THEN t.DataUsage
WHEN @SortColumn = N'OSVersion' AND @SortAsc = 1 THEN t.OSMajorVersion
WHEN @SortColumn = N'OSVersion' AND @SortAsc = 1 THEN t.OSMinorVersion
WHEN @SortColumn = N'OSVersion' AND @SortAsc = 1 THEN t.OSBuildNumber
END) DESC