-- 分頁儲存過程
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
分頁儲存過程
create proc p sobigo percentpage tblname varchar 255 t category 表名 strgetfields varchar 1000 需要返回的列 fldname varchar 255 排序的欄位名 pagesize int 10,頁尺寸 pag...
分頁儲存過程
create procedure pro select pageindex int,pagesize int as select student.sno,student.sname,student.s grade.math,grade.physics,grade.huaxue,grade.chine...
分頁 儲存過程
方法一 任何條件的sql語句 create procedure xiaozhengge sqlstr nvarchar 4000 查詢字串 currentpage int,第n頁 pagesize int 每頁行數 asset nocount on declare p1 int,p1是游標的id r...