CREATE PROCEDURE [Page] 

AS
--无优化倒序
declare @pageSize int   --返回一页的记录数
declare @CurPage int  --页号(第几页)0:第一页;-1最后一页。
declare @Count int
declare @id int

set @pageSize=10
set @CurPage =1


--定位
if @CurPage = -1
begin
 
--最后一页
set rowcount @pageSize
select @id = ProductID from Products   order by ProductID
end

if @CurPage > 0
begin
 
set @Count = @pageSize * (@CurPage -1+ 1
 
set rowcount @Count
 
select @id = ProductID from Products   order by ProductID desc
end

--返回记录
set rowcount @pageSize
select * from Products   where ProductID <=@id order by ProductID desc

set rowcount 0
GO