use TestDB
go
if exists(select name from sysobjects where name='page2005' and type='P')
drop proc page2005
go
create proc page2005
@PageIndex int,
@PageSize int
as
declare @RecordCount int,@PageCount int
select @RecordCount=count(*) from student
set @pagecount=ceiling(@RecordCount*1.0/@PageSize)
if @PageIndex>@pagecount
set @PageIndex = @pagecount-1 --last page
if @PageIndex <0
set @PageIndex = 0 --first page
select sqno,* from
(select sid,deptid,sno,sname,row_number() over (order by sid desc) as sqno from student) as s
where s.sqno > (@PageIndex*@PageSize) and s.sqno <= ((@PageIndex+1)*@PageSize)
exec page2005 10,20