zoukankan      html  css  js  c++  java
  • 有效的分页存储过程

    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

  • 相关阅读:
    Rediect to ...
    [VSTO] warning CS0467 解决方案
    [HTTP]Nonocast.http post方法
    2013年上半年读过的书-无责任书评
    Cordova deploy on Android
    First App on Phonegap | Cordova
    Windows store app[Part 4]:深入WinRT的异步机制
    Windows store app[Part 3]:认识WinRT的异步机制
    Windows store app[Part 2]:全新的File System与Uri不匹配的问题
    Windows store app[Part 1]:读取U盘数据
  • 原文地址:https://www.cnblogs.com/happy-Chen/p/3610926.html
Copyright © 2011-2022 走看看