вторник, 7 октября 2008 г.

Пример пейжинга(Paging) в SQL Server 2005

CREATE PROCEDURE [dbo].[Limit]
-- Add the parameters for the stored procedure here
@Page int,
@PageSize int
AS
SET NOCOUNT ON

;WITH PagedResult AS (SELECT ROW_NUMBER() OVER (ORDER BY ID) AS RowNum, * FROM users)

SELECT * FROM PagedResult

WHERE RowNum BETWEEN

CASE WHEN @Page > 1 THEN (@PageSize * @Page) - @PageSize + 1

ELSE @Page END AND @PageSize * @Page