Data paging in SQL Server CE (Compact Edition)

前端 未结 5 1456
时光取名叫无心
时光取名叫无心 2021-01-11 12:56

I am writing a wpf destop application, and would like to use SQL Server CE as a backend. I\'m trying to come up with a good way to do efficient data paging. In SQL Server

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-11 13:37

    There are a few ways, but the most simplistic way would be like the following:

    Assuming

    1. Page Size = 10
    2. Page = 2

    Then

    1. First TOP = PageSize (10)
    2. Second TOP = PageSize * Page (20)
    
    SELECT
     [Page].[ID],
     [Page].[FirstName],
     [Page].[LastName]
    FROM
    (
    SELECT TOP (10)
     [FirstRows].[ID],
     [FirstRows].[FirstName],
     [FirstRows].[LastName]
    FROM
     (
     SELECT TOP (20)
      [TestTable].[ID],
      [TestTable].[FirstName],
      [TestTable].[LastName]
     FROM
      [TestTable]
     ORDER BY
      [TestTable].[ID] ASC
     ) AS [FirstRows]
    ORDER BY 
     [FirstRows].[ID] DESC
    ) AS [Page]
    ORDER BY
      [Page].[ID] ASC

提交回复
热议问题