国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

分頁存儲過程(用存儲過程實現數據庫的分頁代碼)

2024-08-31 00:58:39
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:


--*******************************************************
--* 分頁存儲過程 *
--* 撒哈拉大森林 *
--* 2010-6-28 *
--*******************************************************

if exists(select * from sysobjects where type='P' and name=N'P_Paging')
drop procedure P_Paging
go

create procedure P_Paging
@SqlStr nvarchar(4000), --查詢字符串
@CurrentPage int, --第N頁
@PageSize int --每頁行數
as
set nocount on
declare @P1 int, --P1是游標的id
@rowcount int
exec sp_cursoropen @P1 output,@SqlStr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select ceiling(1.0*@rowcount/@PageSize) as 總頁數--,@rowcount as 總行數,@CurrentPage as 當前頁
set @CurrentPage=(@CurrentPage-1)*@PageSize+1
exec sp_cursorfetch @P1,16,@CurrentPage,@PageSize
exec sp_cursorclose @P1
set nocount off
go


----創建測試表
--if exists(select * from sysobjects where type='U' and name=N'Test_Students')
-- drop table Test_Students
--go
--create table Test_Students(
-- id int IDENTITY(1,1) not null,
-- name nvarchar(100) not null
--)
--
----創建測試數據
--declare @i int
--set @i = 100000
--while @i>0
-- begin
-- insert into Test_Students values('姓名')
-- set @i = @i - 1
-- end
--
----執行存儲過程
--exec P_Paging 'select * from Test_Students order by id',100,100 --執行
--
----刪除測試表
--if exists(select * from sysobjects where type='U' and name=N'Test_Students')
-- drop table Test_Students
--go

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平南县| 剑阁县| 新密市| 淳安县| 昭平县| 阳曲县| 正宁县| 庆安县| 农安县| 苍南县| 信阳市| 都江堰市| 满城县| 建平县| 亳州市| 瓦房店市| 榆社县| 冕宁县| 五常市| 印江| 封丘县| 牙克石市| 伊吾县| 沂源县| 五指山市| 淳安县| 泸州市| 永顺县| 轮台县| 荥阳市| 南陵县| 罗山县| 河南省| 南溪县| 凌云县| 额济纳旗| 淮阳县| 长顺县| 定兴县| 永和县| 扶余县|