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

发布时间:2022-04-18 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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相关内容感兴趣的读者可查看本站专题:《SQL Server分页技术总结》、《SQL Server查询操作技巧大全》、《SQL Server存储过程技巧大全》、《SQL Server索引操作技巧大全》、《SQL Server常用函数汇总》及《SQL Server日期与时间操作技巧总结

希望本文所述对大家SQL Server数据库程序设计有所帮助。

脚本宝典总结

以上是脚本宝典为你收集整理的sql server实现分页的方法实例分析全部内容,希望文章能够帮你解决sql server实现分页的方法实例分析所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:server分页"