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

  • 相关阅读:
    解决安装vmware-tools出现的“The path "" is not a valid path to the 3.2.0-4-amd64 kernel headers”问题
    页面布局
    CSS属性/尺寸/边框/背景 超级链接
    前端
    索引
    Pymysql
    单表查询,多表查询,子查询
    表的完整性约束
    文件库,文件表,记录的增删改查
    IO多路复用,数据库mysql
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/616679.html
Copyright © 2011-2022 走看看