System Information

Impossible Is Nothing...

导航

[转]一个利用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

(@PageIndex - 1) * @PageSize + 1 and @PageIndex*@PageSize



END

from:http://davidhayden.com/blog/dave/archive/2005/12/30/2652.aspx
Hope this helps

posted on 2006-05-11 16:28  SysInfo  阅读(558)  评论(0编辑  收藏  举报