• 有效的分页存储过程


    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

  • 相关阅读:
    postgresql 配置文件优化
    postgresql 主从配置
    关于 pgsql 数据库json几个函数用法的效率测试
    linux 常用命令大全
    linux 禁ping本机方法
    inotify 心得
    安装PHP扩展
    centos 防火墙配置
    Java好的的工具类:JsonUtils
    Java好的的工具类:JSONResult
  • 原文地址:https://www.cnblogs.com/happy-Chen/p/3610926.html
Copyright © 2020-2023  润新知