我想orderby
在存储过程中使用分页和动态子句(多于一列)。我确实尝试过,但给了我一个错误
看来我不能在 rank() 上使用 Row_number()
窗口函数不能在另一个窗口函数或聚合的上下文中使用。
除了 linq to sql 之外,有没有其他方法可以实现这一目标
SELECT [t8].[AssetId],
[t8].[WorkOrderId],
[t8].[IssueDescription] AS [WorkOrderDescription],
[t8].[value] AS [Type],
[t8].[WorkOrderStatusTypeName] AS [Status],
[t8].[value2] AS [StartDate],
[t8].[CompletedDate] AS [CompleteDate],
[t8].[value22] AS [CompletedBy],
ISNULL([t8].[value3],0) AS [Hours]
FROM (
SELECT ROW_NUMBER()
OVER (ORDER BY CASE WHEN @sortColumnName = 'default' THEN (RANK() over( order by [t7].[WorkOrderStatusTypeId] ASC, [t7].[WorkOrderId])) END ,
CASE WHEN @sortColumnName = 'WorkOrderId' AND @sortOrder = 'asc' THEN [t7].[WorkOrderId] END ASC,
CASE WHEN @sortColumnName = 'WorkOrderId' AND @sortOrder = 'desc' THEN [t7].[WorkOrderId] END DESC
) AS [ROW_NUMBER],
[t7].[AssetId],
[t7].[WorkOrderId],
[t7].[IssueDescription],
[t7].[value],
[t7].[WorkOrderStatusTypeName],
[t7].[value2],
[t7].[CompletedDate],
[t7].[value22],
[t7].[value3]
from --Different tables
) as t8
WHERE [t8].[ROW_NUMBER] BETWEEN ((@pageIndex-1) * @pageSize)+ 1 AND @pageIndex * @pageSize
ORDER BY [t8].[ROW_NUMBER]