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

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

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

2020-07-25 13:25:23
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

--*******************************************************
--* 分頁存儲過程 *
--* 撒哈拉大森林 *
--* 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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 通江县| 湖州市| 温宿县| 库伦旗| 营口市| 隆化县| 长乐市| 卓尼县| 盐亭县| 上犹县| 牙克石市| 郯城县| 阆中市| 武汉市| 涡阳县| 丘北县| 昌乐县| 吉木萨尔县| 长海县| 灵川县| 江达县| 新乡县| 宣城市| 汤原县| 珲春市| 泰和县| 亚东县| 甘泉县| 碌曲县| 图们市| 凤凰县| 灵丘县| 玛纳斯县| 屯昌县| 福安市| 西乌珠穆沁旗| 年辖:市辖区| 松溪县| 托克逊县| 黑水县| 伊吾县|