0

我正在使用 C# 和 SQL Server 2008,在这里我附上我的查询。我想为动态网格视图设置限制。我需要这个查询来在动态网格视图上分页我怎么能

SELECT 
    Item.ItemID,Item.TypeID,Item.StatusID,Item.SeverityID,Item.PriorityID,Item.ProjectID,Item.ReleaseID,
    Item.ClientID,Item.Body,Item.CreatedBy,Item.CreatedDate,Item.ModifiedBy,Item.ModifiedDate,Item.IsActive, 
item.[Subject], Type.Name as Type, status.Name as Status, Project.Name as Project,Release.Name as Release,
Priority.Name as Priority,Severity.Name as Severity,Client.Name as Client,
ROW_NUMBER() OVER (ORDER BY ItemID) AS Rowis

FROM Item (NOLOCK)  
LEFT OUTER JOIN  [Type] (NOLOCK)  ON Item.TypeID = [Type].TypeID
LEFT OUTER JOIN  [Status] (NOLOCK) ON Item.StatusID = [Status].StatusID
LEFT OUTER JOIN [Project] (NOLOCK) ON Item.ProjectID=[Project].ProjectID
LEFT OUTER JOIN [Release] (NOLOCK) ON Item.ReleaseID =[Release].ReleaseID 
LEFT OUTER JOIN [Priority] (NOLOCK) ON Item.PriorityID=[Priority].PriorityID 
LEFT OUTER JOIN [Severity] (NOLOCK) ON Item.SeverityID =[Severity].SeverityID
LEFT OUTER JOIN [Client] (NOLOCK) ON Item.ClientID =[Client].ClientID 
4

1 回答 1

1

@PageIndex 和@PageSize 是从应用层发送的参数。

DECLARE @PageIndex INT = 1
DECLARE @PageSize INT = 10

SELECT * FROM 
(
    SELECT 
        Item.ItemID,Item.TypeID,Item.StatusID,Item.SeverityID,Item.PriorityID,Item.ProjectID,Item.ReleaseID,
        Item.ClientID,Item.Body,Item.CreatedBy,Item.CreatedDate,Item.ModifiedBy,Item.ModifiedDate,Item.IsActive, 
    item.[Subject], Type.Name as Type, status.Name as Status, Project.Name as Project,Release.Name as Release,
    Priority.Name as Priority,Severity.Name as Severity,Client.Name as Client,
    ROW_NUMBER() OVER (ORDER BY ItemID) AS Rowis

    FROM Item (NOLOCK)  
    LEFT OUTER JOIN  [Type] (NOLOCK)  ON Item.TypeID = [Type].TypeID
    LEFT OUTER JOIN  [Status] (NOLOCK) ON Item.StatusID = [Status].StatusID
    LEFT OUTER JOIN [Project] (NOLOCK) ON Item.ProjectID=[Project].ProjectID
    LEFT OUTER JOIN [Release] (NOLOCK) ON Item.ReleaseID =[Release].ReleaseID 
    LEFT OUTER JOIN [Priority] (NOLOCK) ON Item.PriorityID=[Priority].PriorityID 
    LEFT OUTER JOIN [Severity] (NOLOCK) ON Item.SeverityID =[Severity].SeverityID
    LEFT OUTER JOIN [Client] (NOLOCK) ON Item.ClientID =[Client].ClientID 
)
AS Results
WHERE Rowis BETWEEN (@PageIndex - 1) * @PageSize + 1 AND @PageIndex * @PageSize --Paging
于 2012-12-05T13:00:56.943 回答