分页之存储过程

注意:

1.分页一般结合分页控件使用

2.分页控件必须要知道总行数,这样才可以展示出总共有多少页码

3.最好结合分页存储过程使用

一.分页存储过程

CREATE PROCETURE USP_GetListByPage

@pageIndex int--页码

,@pageSize int--每页显示的数据行数

,@totalCount int out --总行数

AS

BEGIN

--1.0定义开始和结束索引变量

declare @startIndex int,@endIndex int

--2.0根据外部传入给存储过程的参数进行初始化

set @startIndex=(@pageIndex-1)*@pageSize

set @endIndex=@pageIndex*@pageSize

--3.0获取分页数据

select * from(

select row=ROW_NUMBER() OVER(ORDER BY Id DESC),* from 表名 where IsDel=0

) as t

where t.row>@startIndex and t.row<=@endIndex

--4.0 获取当前满足条件的数据总行数

select @totalcount=COUNT(1) from 表名 where IsDel=0

END

GO

posted @ 2014-11-11 22:01  沉住气埋头苦干  阅读(160)  评论(0编辑  收藏  举报