真正的分页存储过程

IF OBJECT_ID('jjp_CategoryList_Get') IS NOT NULL
    DROP PROCEDURE jjp_CategoryList_Get;

GO

CREATE PROCEDURE jjp_CategoryList_Get
(
    @pageIndex int,
    @PageSize int,
    @Records int output
)
AS
begin
    with tmpTable as
    (
    select id, c1, c2 , row_number() over( order by id) as rownum from dbo.t1
    )
    select *  from tmpTable where  rownum between (@pageIndex-1)*@PageSize+1 and @PageIndex*@PageSize;
    select @Records=count(*) from dbo.t1;

end

posted @ 2013-03-24 14:03  侯伟东  阅读(138)  评论(0编辑  收藏  举报