sql server实现分页的方法实例分析
更新时间:2017年03月13日 11:35:13 作者:继续去踢波
这篇文章主要介绍了sql server实现分页的方法,结合实例形式总结分析了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数据库程序设计有所帮助。
相关文章
轻量级数据库SQL Server Express LocalDb介绍
这篇文章介绍了轻量级数据库SQL Server Express LocalDb,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2022-06-06
SQLSERVER查看数据库日志方法与语句示例代码(已亲测)
在数据库使用很久后日志文件会累计的越来越大,如果硬盘空间不足可能会导致宕机,下面这篇文章主要给大家介绍了关于SQLSERVER查看数据库日志方法与语句的相关资料,需要的朋友可以参考下2023-03-03
SQL Server提示"选定的用户拥有对象,所以无法除去该用户”
今天在帮朋友弄一台服务器的时候当我需要删除一个数据库里的用户时,提示如下错误信息: "选定的用户拥有对象,所以无法除去该用户" 如何解决呢?2009-04-04


最新评论