SQL Server 2005新增功能--Row_NUMBER() 分页查询
我的测试代码
开发圣经上的示例代码
SELECT * FROM
(
SELECT ROW_NUMBER() OVER(ORDER BY DATE) ROWNUM, * FROM BAS_CALENDAR
) CAL
WHERE ROWNUM BETWEEN (50*1)+1 AND 50*2
ORDER BY DATE ASC
(
SELECT ROW_NUMBER() OVER(ORDER BY DATE) ROWNUM, * FROM BAS_CALENDAR
) CAL
WHERE ROWNUM BETWEEN (50*1)+1 AND 50*2
ORDER BY DATE ASC
开发圣经上的示例代码
CREATE PROC spGetPages2 @iRowCount INT, @iRowPageNo INT
AS
SELECT * FROM (
SELECT ROW_NUMBER() OVER(ORDER BY ProductID ASC) RowNum, * FROM Production.Product ) OrderData
WHERE RowNum BETWEEN @iRowCount*(@iPageNo-1)+1 and @iRowCount*@iPageNo
ORDER BY ProductID ASC
GO
EXEC spGetPages2 10,20
AS
SELECT * FROM (
SELECT ROW_NUMBER() OVER(ORDER BY ProductID ASC) RowNum, * FROM Production.Product ) OrderData
WHERE RowNum BETWEEN @iRowCount*(@iPageNo-1)+1 and @iRowCount*@iPageNo
ORDER BY ProductID ASC
GO
EXEC spGetPages2 10,20