zoukankan      html  css  js  c++  java
  • 很强大的sqlserver分页存储过程

    代码
    -- ================================================
    --
    Template generated from Template Explorer using:
    --
    Create Procedure (New Menu).SQL
    --
    --
    Use the Specify Values for Template Parameters
    --
    command (Ctrl-Shift-M) to fill in the parameter
    --
    values below.
    --
    --
    This block of comments will not be included in
    --
    the definition of the procedure.
    --
    ================================================
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    --
    Author: <Author,,Name>
    --
    Create date: <Create Date,,>
    --
    Description: <Description,,>
    --
    =============================================
    CREATE PROCEDURE ContractRecord_GetAll_Page
    -- Add the parameters for the stored procedure here
    @filterExpression NVARCHAR(2000),
    @sortExpression NVARCHAR(100),
    @rowIndex INT = 0,
    @pageSize INT = 24,
    @TotalRecords INT OUTPUT
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    CREATE TABLE #GoodsKind (RowNumber INT, ContractID uniqueidentifier)
    IF ((@sortExpression IS NULL) OR (LEN(@sortExpression) = 0))
    BEGIN
    SET @sortExpression = 'ContractCode asc'
    END

    DECLARE @SQLString NVARCHAR(MAX)
    SET @SQLString = N'
    INSERT INTO #GoodsKind
    SELECT ROW_NUMBER() OVER (ORDER BY
    ' + @sortExpression + ') AS RowNumber, ContractID
    FROM vw_ContractRecord
    '
    IF ((@filterExpression IS NOT NULL) AND (LEN(@filterExpression) > 0))
    BEGIN
    SET @SQLString = @SQLString + ' WHERE ' + @filterExpression
    END

    EXECUTE sp_executesql @SQLString

    SELECT @TotalRecords = COUNT(ContractID)
    FROM #GoodsKind
    -- Insert statements for procedure here
    SELECT p.ContractID,EntCode,ContractCode,GoodsLimitDepartment,Supplier,Merchandiser,ContractTime,
    Remark,RealAmount,TaxAmount,RealAndTaxAmount,OperatorName,InputDate
    FROM #GoodsKind as p INNER JOIN vw_ContractRecord as C on p.ContractID = C.ContractID
    WHERE p.RowNumber BETWEEN @rowIndex + 1 AND @rowIndex + @PageSize ORDER BY p.RowNumber
    END
    GO
  • 相关阅读:
    java 对象的创建
    可重入锁
    guava multimap介绍
    Tomcat运行机制
    GC垃圾收集算法
    GC判断哪些内存需要回收
    JVM类加载器以及双亲委派模型
    深入分析ConcurrentHashMap
    BeanCopier类
    Quartz技术原理
  • 原文地址:https://www.cnblogs.com/larson/p/1802997.html
Copyright © 2011-2022 走看看