zoukankan      html  css  js  c++  java
  • 分页存储过程-- 分页存储过程

    -- 分页存储过程
    ALTER proc [dbo].[p_pageShow](
    @pageSize int, --每页大小
    @currentPage int out,  --当前页
    @houseName nvarchar(50), --房产名称 
    @totalCount int out, --总记录数
    @totalPage int out --总页数
    )
    as
    begin
    --纠正当前页<1的情况
    if @currentPage < 1
    set @currentPage = 1
    --查出总记录数
    select @totalCount = count(*) from House where HouseName like '%' + @houseName + '%'
    --查出总页数
    if @totalCount % @pageSize = 0
    set @totalPage = @totalCount / @pageSize
    else
    set @totalPage = @totalCount / @pageSize + 1
    --纠正当前页 > 总页数的情况
    if @currentPage > @totalPage
    set @currentPage = @totalPage
    --分页查询
    select * from
    (select h.HouseId, h.HouseName, h.HouseType, h.Leixing, h.Floor, h.TotalFloor, h.Rent, h.Addr, a.AreaName,
     ROW_NUMBER() over (order by houseId) rn from house h left join area a on h.AreaId = a.AreaId
      where h.HouseName like '%' + @houseName + '%' ) t1
    where rn between (@currentPage - 1) * @pageSize + 1 and @currentPage * @pageSize
    end

  • 相关阅读:
    全局变量 和 局部变量
    函数
    字符串拼接
    集合
    字典
    元祖
    列表
    Python 字符串 小练习
    ssm多数据源配置
    JAVA笔记:double四舍五入并保留两位小数的方法
  • 原文地址:https://www.cnblogs.com/gc1229/p/13072636.html
Copyright © 2011-2022 走看看