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

所属分类: 数据库 / MsSql 阅读数: 605
收藏 0 赞 0 分享

本文实例讲述了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数据库图文教程
收藏 0 赞 0 分享

一个SQL语句获得某人参与的帖子及在该帖得分总和

一个SQL语句获得某人参与的帖子及在该帖得分总和
收藏 0 赞 0 分享

通用分页存储过程,源码共享,大家共同完善

通用分页存储过程,源码共享,大家共同完善
收藏 0 赞 0 分享

SQL查找某一条记录的方法

SQL查找某一条记录的方法
收藏 0 赞 0 分享

使用 GUID 值来作为数据库行标识讲解

使用 GUID 值来作为数据库行标识讲解
收藏 0 赞 0 分享

非常详细的SQL--JOIN之完全用法

非常详细的SQL--JOIN之完全用法
收藏 0 赞 0 分享

收缩后对数据库的使用有影响吗?

收缩后对数据库的使用有影响吗?
收藏 0 赞 0 分享

mssql server 存储过程里,bulk insert table from '路径+文件',路径固定,文件名不固定的实现方法

mssql server 存储过程里,bulk insert table from '路径+文件',路径固定,文件名不固定的实现方法
收藏 0 赞 0 分享

请问在mssql“SQL事件探查器”里表格的标题,如CPU,Read,Write,Duration,SPID.........的解释

请问在mssql“SQL事件探查器”里表格的标题,如CPU,Read,Write,Duration,SPID.........的解释
收藏 0 赞 0 分享

SQL Server 2000的安全配置

SQL Server 2000的安全配置
收藏 0 赞 0 分享
查看更多