加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SqlServer分页存储过程

发布时间:2020-12-12 13:31:01 所属栏目:MsSql教程 来源:网络整理
导读:高效分页语句: 1 , row_number() select * from ( select *, ROW_NUMBER () over ( order by rpId ) as row from Ou_RolePermission ) as t where t . row ? 0 and? ? t . row= 10 2,--top 分页查询 select top 10 * from Ou_RolePermission where rpId no

高效分页语句:

1row_number()

select * from ( select *,ROW_NUMBER() over(order by rpId) as row from Ou_RolePermission)as t where t.row?>0 and??t.row<=10

2,--top 分页查询

select top 10 * from Ou_RolePermission whererpId not in(select top 10 rpId from Ou_RolePermission)

?

分页存储过程:

create PROCEDURE GetPagedData

@pageIndex int = 1,--页码

@pageSize int =10,--页容量

@isDel bit=0,--是否删除

@rowCount float output,--输出总行数

@pageCount float output--输出总页数

AS

BEGIN

??? select @rowCount = COUNT(cid) from Classes where CIsDel=@isDel? --求总行数

??? set @pageCount= CEILING(@rowCount / @pageSize)--使用天花板函数,将带小数的数值,加去小数

?? select *from (

????? select ROW_NUMBER() over(order by cid) as rownum ,* from Classes where CIsDel=@isDel

?? )astemp where temp.rownum >(@pageIndex-1)*@pageSize and temp.rownum <=@pageIndex*@pageSize

END

GO

?

declare @rc int,@pc int

exec GetPagedData3 , 10 ,1, @rc output,@pc output

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读