sqlserver分页的两种写法分别介绍

前端之家收集整理的这篇文章主要介绍了sqlserver分页的两种写法分别介绍前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

第一种是最传统的写法,用存储过程中的变量作为分页的乘数
<div class="codetitle"><a style="CURSOR: pointer" data="77734" class="copybut" id="copybut77734" onclick="doCopy('code77734')"> 代码如下:

<div class="codebody" id="code77734">
[c-sharp] view plaincopyprint?create proc p_paged1
@pageSize int,@currentPage int
as
select top (@pageSize) from student
where id not in
(select top (@pageSize
(@currentPage-1)) id from student)
go
exec p_paged1 2,3
create proc p_paged1
@pageSize int,3

--sql Server2005以后的分页语句
<div class="codetitle"><a style="CURSOR: pointer" data="69448" class="copybut" id="copybut69448" onclick="doCopy('code69448')"> 代码如下:
<div class="codebody" id="code69448">
[c-sharp] view plaincopyprint?create proc p_paged2
@pageStart int,@pageEnd int
as
select from
(select
,row_number() over(order by id desc) as rnum
from student) t
where t.rnum between @pageStart and @pageEnd
go exec p_paged2 5,10

猜你在找的MsSQL相关文章