.NET中实现分页的存储过程

alter proc getdatabypageindex
@PageIndex int=1, --页码
@PageSize int=6, --分页规格
@PageCount int output --页码总数
as
declare @StartIndex int,@EndIndex int
set @StartIndex=(@PageIndex-1)*@PageSize+1
set @EndIndex=@PageIndex*@PageSize

select * from
(
select ROW_NUMBER() over(order by id asc) as RowNum,*from dbo.Administrator_ManageFunction
) as tempTable
where RowNum between @StartIndex and @EndIndex
declare @PageCount1 int
set @PageCount1=(select COUNT(*) from dbo.Administrator_ManageFunction)%@PageSize
declare @PageCount2 int
set @PageCount2=(select COUNT(*) from dbo.Administrator_ManageFunction)/@PageSize
if(@PageCount1=0)
begin
set @PageCount=@PageCount2
end
else
begin
set @PageCount=@PageCount2+1
end
go

declare @PageCount int
exec getdatabypageindex 1,13,@PageCount output
select @PageCount

posted on 2016-01-14 19:36  闷闷的小六六  阅读(207)  评论(0编辑  收藏  举报

导航