How do I implement pagination in SQL for MS Access?

前端 未结 6 1474
自闭症患者
自闭症患者 2020-11-30 06:02

I\'m accessing a Microsoft Access 2002 database (MDB) using ASP.NET through the OdbcConnection class, which works quite well albeit very slowly.

My quest

6条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 06:52

    See astander's answer for the original answer, but here's my final implementation that takes into account some ODBC parser rules (for the first 15 records after skipping 30):

    SELECT *
    FROM (
      SELECT Top 15 -- = PageSize
      *
      FROM
      (
       SELECT TOP 45 -- = StartPos + PageSize
       *
       FROM tblClient
       ORDER BY Client
      ) AS sub1
      ORDER BY sub1.Client DESC
     ) AS clients
    ORDER BY Client
    

    The difference here is that I need the pagination to work when sorted by client name, and I need all columns (well, actually just a subset, but I sort that out in the outer-most query).

提交回复
热议问题