• 有效的分页存储过程


    CREATE

    PROCEDURE [dbo].[Profile_GET]

    @PageSize

    int=null,

        @CurrentPage

    int=null,

        @SortExpression   

    nvarchar(max)=null

    AS

    BEGIN

       

    SETNOCOUNTON

       

    DECLARE @SqlString nvarchar(max)

       

    Declare @UpperBand int

       

    Declare @LowerBand int       

       

       

    SET @LowerBand  =(@CurrentPage - 1)* @PageSize

       

    SET @UpperBand  =(@CurrentPage * @PageSize)+ 1   

       

    BEGIN

           

    SET @SqlString='WITH tempProfile AS

            (                   

                SELECT

                    [ProfileId],

                    [Name],

                    [Address],

                    [Email],

                    [Mobile],

                    [Active] = CASE [IsActive] WHEN 1

                    THEN ''Active'' WHEN 0 THEN ''DeActive'' END,                           

                    ROW_NUMBER() OVER (ORDER BY '

    + @SortExpression +' ) AS RowNumber                

                    FROM [dbo].[Profile]

            )    

            SELECT

                [ProfileId],

                [Name],

                [Address],

                [Email],

                [Mobile],

                [Active]                                       

            FROM

                tempProfile

            WHERE

                RowNumber > '

    +CONVERT(VARCHAR,@LowerBand)+' AND RowNumber < '+CONVERT(VARCHAR, @UpperBand)

               

    +' ORDER BY '+ @SortExpression  ;         

       

       

    EXECsp_executesql@SqlString

       

    END

    END

    ;

    CREATE

    PROCEDURE [dbo].[Profile_Total]

    AS

    BEGIN

       

    SETNOCOUNTON

       

    SELECTCOUNT(*)FROMProfile

    END

  • 相关阅读:
    前端诡异参数start
    JDK常用命令(二)jstack
    JDK常用命令(一)jps、jstat
    C#反射之基础应用
    c#实现随鼠标移动窗体
    c# 使用api函数 ShowWindowAsync 控制窗体
    简单例子快速了解事件处理和委托 event delegate
    通过 WIN32 API 实现嵌入程序窗体
    C# 轻松实现对窗体(Form)换肤[转]
    C#正则表达式匹配HTML中的图片路径
  • 原文地址:https://www.cnblogs.com/happy-Chen/p/3610926.html
Copyright © 2020-2023  润新知