您的位置:首页 > 数据库

sql分页定义存储过程

2012-02-27 20:29 295 查看
USE [cellcenter]

GO

/****** Object: StoredProcedure [dbo].[fenyede] Script Date: 02/27/2012 20:30:54 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

createPROCEDURE [dbo].[fenyede]

@pageSize int, --每页记录数量

@pageCount int output, --总页数

@pageIndex int --当前页索引号

AS

BEGIN

declare @totalRecords int

select @totalRecords = count(id) from users

if(@totalRecords % @pageSize = 0)

set @pageCount = @totalRecords / @pageSize;

else

set @pageCount = @totalRecords / @pageSize +1;

with temp as (select row_number() over (order by id) as sid,* from users)

select username,xingming,power from temp where power !='客户' and id between (@pageIndex -1)*@pageSize +1 and @pageIndex * @pageSize

return @totalRecords

end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: