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