[转]一个利用Sql Server 20005的 ROW_NUMBER Function 的分页存储过程.
ROW_NUMBER returns a sequential number, starting at 1, for each row returned in a resultset.
CREATE PROCEDURE dbo.ShowLog
@PageIndex INT,
@PageSize INT
AS
BEGIN
WITH LogEntries AS (
SELECT ROW_NUMBER() OVER (ORDER BY Date DESC)
AS Row, Date, Description
FROM LOG)
SELECT Date, Description
FROM LogEntries
WHERE Row between
END
from:http://davidhayden.com/blog/dave/archive/2005/12/30/2652.aspx
Hope this helps
CREATE PROCEDURE dbo.ShowLog
@PageIndex INT,
@PageSize INT
AS
BEGIN
WITH LogEntries AS (
SELECT ROW_NUMBER() OVER (ORDER BY Date DESC)
AS Row, Date, Description
FROM LOG)
SELECT Date, Description
FROM LogEntries
WHERE Row between
(@PageIndex - 1) * @PageSize + 1 and @PageIndex*@PageSize
END
from:http://davidhayden.com/blog/dave/archive/2005/12/30/2652.aspx
Hope this helps