`
923723914
  • 浏览: 634849 次
文章分类
社区版块
存档分类
最新评论

SqlServer分页存储过程

 
阅读更多

高效分页语句:

1row_number()

select * from ( select *,ROW_NUMBER() over(order by rpId) as row from Ou_RolePermission)as t where t.row>0 andt.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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics