zoukankan      html  css  js  c++  java
  • 写了一个分页存储过程把总记录数也写到返回表的每行了

    ALTER PROCEDURE [dbo].[a_Example]
     @startIndex INT ,--每页的开始记录的索引
     @pageSize INT --每页记录数
    AS
    --取出记录总数 插入@RecordCountTable临时表
    declare @RecordCountTable table(RecordCount int)
    insert into @RecordCountTable SELECT count(*) AS RecordCount FROM InOut_InOut_InOutBed
    --直接用
    begin
     select * from
        (
          SELECT row_number() OVER (ORDER BY InOutBedID DESC)AS Row,*
       from
            InOut_InOut_InOutBed
       LEFT JOIN
            @RecordCountTable ON 1=1
     )
        as
          TemporaryTable
     where
       row between @startIndex and @startIndex+@pageSize-1
    end

    或者:
    ALTER PROCEDURE [dbo].[a_Example]
     @startIndex INT ,--每页的开始记录的索引
     @pageSize INT --每页记录数
    AS
    --取出记录总数 插入@RecordCountTable临时表
    declare @RecordCountTable table(RecordCount int)
    insert into @RecordCountTable SELECT count(*) AS RecordCount FROM InOut_InOut_InOutBed
    --虚拟视图
    begin
    --取出内容 每行左连记录总数 虚拟视图orderList
    WITH orderList AS
    (
    SELECT row_number() OVER (ORDER BY InOutBedID DESC)AS Row,*
    from InOut_InOut_InOutBed
    LEFT JOIN @RecordCountTable ON 1=1
    )
    --取出虚拟视图orderList中分页内容
    SELECT *
    FROM orderlist
    WHERE row between @startIndex and @startIndex+@pageSize-1
    end

  • 相关阅读:
    C语言实现单处理器的进程管理
    哈夫曼编码
    栈与队列的应用:停车场管理
    带括号的表达式求值
    表达式求值(无括号)
    处理代码异常
    在Pyhon中使用:网络编程 & 接口开发
    枚举函数(enumerate)
    【Redis】数据库相关操作
    数据库(新增数据、建立数据表、复制、对比表数据)
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/616679.html
Copyright © 2011-2022 走看看