45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:sql Server实现分页实例有哪些?

sql Server实现分页实例有哪些?

2017-08-23 07:43:30 来源:www.45fan.com 【

sql Server实现分页实例有哪些?

本文实例讲述了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数据库程序设计有所帮助。


本文地址:http://www.45fan.com/a/question/91461.html
Tags: 实现 sql Server
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部