CREATEPROC GetList2 ( @iCurPage INT, @iPageSize INT ) AS -- local vars DECLARE @total INT DECLARE @start INT DECLARE @end INT DECLARE @maxid INT DECLARE @minid INT --SET @iPageSize = 10 --SET @iCurPage = 1 SET @start = (@iCurPage-1) * @iPageSize +1 SET @end = @start + @iPageSize -1 DECLARE pagecursor CURSOR SCROLL FOR SELECT ProductID FROM Products ORDERBY ProductID DESC OPEN pagecursor SET @total = @@CURSOR_ROWS FETCH ABSOLUTE @start FROM pagecursor INTO @minid IF @end > @total FETCH LAST FROM pagecursor INTO @maxid ELSE FETCH ABSOLUTE @end FROM pagecursor INTO @maxid CLOSE pagecursor DEALLOCATE pagecursor SELECT* FROM Products WHERE ProductID BETWEEN @maxid AND @minid ORDERBY ProductID DESC --使用方法 USE NorthWind EXEC GetList2 1,10