欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

sql server实现分页的方法实例分析

程序员文章站 2022-03-25 09:48:31
本文实例讲述了sql server实现分页的方法。分享给大家供大家参考,具体如下: declare @index int,@num int set @index...

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