• Paging


    USE [Demo]
    GO

    /****** Object: StoredProcedure [dbo].[sp_Page] Script Date: 02/19/2014 21:26:34 ******/
    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    --declare @TotalCount int 
    --exec Page 8,0,'S_Name','desc','%周%','',@TotalCount output
    --select @TotalCount

    ALTER proc [dbo].[sp_Page]
    @PageSize int,
    @PageCurrent int,
    @SortField varchar(20),
    @SortType varchar(20),
    @S_Name nvarchar(100),
    @C_ID char(2),
    @TotalCount int output
    as
    begin
    declare @SelectSql nvarchar(2000)
    declare @CountSql nvarchar(2000)
    declare @WhereSql nvarchar(2000)
    declare @StartRow int=((@PageCurrent-1)*@PageSize+1)
    declare @EndRow int=@PageCurrent*@PageSize

    --排序字段
    if @SortField is null
    begin
    set @SortField=N'ID'
    set @SortType=N'ASC'
    end
    --条件查询
    set @WhereSql=N'WHERE 1=1 '

    if ltrim(rtrim(@S_Name)) is not null and Ltrim(rtrim(@S_Name))<>''
    set @WhereSql+=N'And S_Name like ''%'+Ltrim(rtrim(@S_Name))+'%'''
    if Ltrim(rtrim(@C_ID)) is not null and Ltrim(rtrim(@C_ID))<>''
    set @WhereSql +=N'AND C_ID = '+Ltrim(rtrim(@C_ID))+''

    set @SelectSql=N'
    select 
    TT.RowId
    ,ID
    ,TT.S_Name
    from (select
    ROW_NUMBER() over(order by '+@SortField+' '+@SortType+' ) as RowId
    ,ID
    ,S_Name
    from dbo.Student WITH(NOLOCK)
    '+@WhereSql+'
    )TT
    where TT.RowId between '+cast(@StartRow as varchar(max))+' and '+cast(@EndRow as varchar(max))+''
    set @CountSql=N'Select @TotalCount =COUNT(*) From dbo.Student A WITH(NOLOCK)'+@WhereSql



    EXEC(@SelectSql)
    --EXEC sp_executesql @SelectSql,
    --N'@S_Name NVARCHAR(100),
    -- @C_ID NVARCHAR(100),
    -- @SortType NVARCHAR(100),
    -- @SortField NVARCHAR(100),
    -- @PageSize INT,
    -- @PageCurrent INT',
    -- @S_Name,
    -- @C_ID,
    -- @SortType,
    -- @SortField,
    -- @PageSize,
    -- @PageCurrent
    --EXEC @CountSql
    EXEC sp_executesql @CountSql,
    N'@S_Name NVARCHAR(100),
    @C_ID char(2),
    @TotalCount int output',
    @S_Name,
    @C_ID,
    @TotalCount output 

    end

    GO

  • 相关阅读:
    教育是什么?
    关于CTime::Format在Unicode下的输出问题及解决办法
    COleDateTime在Unicode下,Format函数会有问题。
    UNICODE字符集
    处理字符串String类和正则表达式
    关于datatable linq的转换
    js
    HDU 3874 Necklace
    HDU 1520 Anniversary party
    HDU 4314 Save the dwarfs
  • 原文地址:https://www.cnblogs.com/TddCoding/p/3565381.html
Copyright © 2020-2023  润新知