復(fù)制代碼 代碼如下:
--*******************************************************
--* 分頁存儲過程 *
--* 撒哈拉大森林 *
--* 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 --每頁行數(shù)
as
set nocount on
declare @P1 int, --P1是游標(biāo)的id
@rowcount int
exec sp_cursoropen @P1 output,@SqlStr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select ceiling(1.0*@rowcount/@PageSize) as 總頁數(shù)--,@rowcount as 總行數(shù),@CurrentPage as 當(dāng)前頁
set @CurrentPage=(@CurrentPage-1)*@PageSize+1
exec sp_cursorfetch @P1,16,@CurrentPage,@PageSize
exec sp_cursorclose @P1
set nocount off
go
----創(chuàng)建測試表
--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
--)
--
----創(chuàng)建測試數(shù)據(jù)
--declare @i int
--set @i = 100000
--while @i>0
-- begin
-- insert into Test_Students values('姓名')
-- set @i = @i - 1
-- end
--
----執(zhí)行存儲過程
--exec P_Paging 'select * from Test_Students order by id',100,100 --執(zhí)行
--
----刪除測試表
--if exists(select * from sysobjects where type='U' and name=N'Test_Students')
-- drop table Test_Students
--go
您可能感興趣的文章:- sqlserver數(shù)據(jù)庫使用存儲過程和dbmail實現(xiàn)定時發(fā)送郵件
- 用存儲過程向數(shù)據(jù)庫存值的具體實現(xiàn)
- MSSQL監(jiān)控數(shù)據(jù)庫的DDL操作(創(chuàng)建,修改,刪除存儲過程,創(chuàng)建,修改,刪除表等)
- sqlSQL數(shù)據(jù)庫怎么批量為存儲過程/函數(shù)授權(quán)呢?
- mysql 導(dǎo)入導(dǎo)出數(shù)據(jù)庫以及函數(shù)、存儲過程的介紹
- Oracle中 關(guān)于數(shù)據(jù)庫存儲過程和存儲函數(shù)的使用
- sql處理數(shù)據(jù)庫鎖的存儲過程分享
- SQL Server中通過擴(kuò)展存儲過程實現(xiàn)數(shù)據(jù)庫的遠(yuǎn)程備份與恢復(fù)
- MSSQL MySQL 數(shù)據(jù)庫分頁(存儲過程)
- 從創(chuàng)建數(shù)據(jù)庫到存儲過程與用戶自定義函數(shù)的小感
- SQLserver 數(shù)據(jù)庫危險存儲過程刪除與恢復(fù)方法
- sqlserver關(guān)于分頁存儲過程的優(yōu)化【讓數(shù)據(jù)庫按我們的意思執(zhí)行查詢計劃】
- mysql 查詢數(shù)據(jù)庫中的存儲過程與函數(shù)的語句
- 為數(shù)據(jù)庫生成某個字段充填隨機(jī)數(shù)的存儲過程
- sql 判斷數(shù)據(jù)庫,表,存儲過程等是否存在的代碼
- Oracle存儲過程之?dāng)?shù)據(jù)庫中獲取數(shù)據(jù)實例
- sqlserver 復(fù)制表 復(fù)制數(shù)據(jù)庫存儲過程的方法
- 積分獲取和消費(fèi)的存儲過程學(xué)習(xí)示例