浪客的 SQL Server 2005 分页 存储过程

时间:2015/12/1 10:19:00来源:互联网 作者:flyso 点击: 873 次

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go



Create PROCEDURE [dbo].[aspnet_Customer.Msg_GetMsgByProfileId]
(
    @PageSize INT,
    @PageIndex INT,
    @ProfileId INT
)
AS
BEGIN
    DECLARE @PageLowerBound INT;
    DECLARE @PageUpperBound INT;
    DECLARE @TotalRecords   INT;
    DECLARE @TotalRecords INT
    SET @PageLowerBound=@PageSize * (@PageIndex-1);
    SET @PageUpperBound = @PageSize - 1 + @PageLowerBound;
    WITH MyMsg AS
    (
    Select ROW_NUMBER() OVER(ORDER BY ID DESC) AS Rownum,
    Id,Msg,Status FROM Customer.Msg Where @ProfileId=ProfileId
    )
    Select Id,Msg,Status
    FROM MyMsg
    Where Rownum>=@PageLowerBound AND Rownum<=@PageUpperBound;
    @TotalRecords=@@ROWCOUNT
END

Copyright © 2005 - 2016 flyso.cn. 飞搜 版权所有 鄂ICP备11002783号-3