如何在tsql中的with case子句上的行\ number()中添加多个排序列

cyvaqqii  于 2021-08-13  发布在  Java
关注(0)|答案(0)|浏览(211)

如何在(order by)上添加多个order by row\ U number
我有这个代码,但似乎不起作用

;WITH CTE_Results AS
(
    SELECT ROW_NUMBER() OVER (ORDER BY
    CASE WHEN @lSortCol = @firstNameLit AND @sortDirection=@ascLit THEN [FirstName] END ASC,
    CASE WHEN @lSortCol = @firstNameLit AND @sortDirection=@descLit THEN [FirstName] END DESC,

    CASE WHEN @lSortCol = @lastNameLit AND @sortDirection=@ascLit THEN [LastName] END ASC,
    CASE WHEN @lSortCol = @lastNameLit AND @sortDirection=@descLit THEN [LastName] END DESC,
    --Sort Column no match
    CASE WHEN @sortDirection=@ascLit THEN [LastName] END ASC, [FirstName] ASC,  --This doesn't work
    CASE WHEN @sortDirection=@descLit THEN [LastName] END DESC, [FirstName] ASC  --This doesn't work

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题