程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> 更多數據庫知識 >> sql server實現分頁的方法實例分析,sql實例分析

sql server實現分頁的方法實例分析,sql實例分析

編輯:更多數據庫知識

sql server實現分頁的方法實例分析,sql實例分析


本文實例講述了sql server實現分頁的方法。分享給大家供大家參考,具體如下:

declare @index int,@num int
set @index = 1--當前頁
set @num = 2--單頁包含的行數
--分頁1
select top (@num) *
from ppohd
where doccode not in
(
  select top (@num * (@index -1)) doccode
  from ppohd
  order by doccode
)
order by doccode
--分頁2
select top (@num) *
from ppohd
where doccode >=
(
  select max(doccode)
  from
  (
    select top (@num * (@index - 1) + 1) doccode
    from ppohd
    order by doccode
  ) as tb
)
--分頁3
select top (@num) *
from
(
  select ppohd.doccode as 'mydoccode',row_number() over (order by doccode) as sno,*
  from ppohd
) as tb
where tb.sno >= @num * (@index - 1) + 1
--分頁4
select *
from
(
  select ppohd.doccode as 'mydoccode', row_number() over(order by doccode) as sno,*
  from ppohd
) as tb
where tb.sno between (@num * (@index - 1) + 1) and (@num * @index)

更多關於SQL Server相關內容感興趣的讀者可查看本站專題:《SQL Server分頁技術總結》、《SQL Server查詢操作技巧大全》、《SQL Server存儲過程技巧大全》、《SQL Server索引操作技巧大全》、《SQL Server常用函數匯總》及《SQL Server日期與時間操作技巧總結》

希望本文所述對大家SQL Server數據庫程序設計有所幫助。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved