学习存储过程的时候参看的两个DVBBS的存储过程和两个初步了解后自己写的存储过程(带分页的)
2005-12-23 17:16
771 查看
<dvbbs7>
================================
ALTER PROCEDURE dv_list
@boardid int=1,
@pagenow int=1, --当前页数
@pagesize int=1, --定义每页面帖子数目
@tl int=0, --按时间段查询
@topicmode int=0, --专题
@totalrec int output
AS
set nocount on
declare @int_topnum int
declare @int_timenum int
declare @var_times varchar(5000)
if @pagenow>1
if @topicmode>0
begin
select @int_timenum=(@pagenow-1)*@pagesize
set rowcount @int_timenum
select @var_times=lastposttime from Dv_Topic where boardID=@boardID and istop = 0 and mode=@topicmode ORDER BY lastposttime desc
set rowcount @pagesize
select TopicID,boardid,title,postusername,postuserid,dateandtime,child,hits,votetotal,lastpost,lastposttime,istop,isvote,isbest,locktopic,Expression,TopicMode,Mode from dv_topic where boardID=@boardID and istop = 0 and mode=@topicmode and lastposttime < @var_times ORDER BY lastposttime desc
set nocount off
return
end
else
begin
select @int_timenum=(@pagenow-1)*@pagesize
set rowcount @int_timenum
select @var_times=lastposttime from Dv_Topic where boardID=@boardID and istop = 0 ORDER BY lastposttime desc
set rowcount @pagesize
select TopicID,boardid,title,postusername,postuserid,dateandtime,child,hits,votetotal,lastpost,lastposttime,istop,isvote,isbest,locktopic,Expression,TopicMode,Mode from dv_topic where boardID=@boardID and istop = 0 and lastposttime < @var_times ORDER BY lastposttime desc
set nocount off
return
end
else
if @topicmode>0
begin
set rowcount @pagesize
select TopicID,boardid,title,postusername,postuserid,dateandtime,child,hits,votetotal,lastpost,lastposttime,istop,isvote,isbest,locktopic,Expression,TopicMode,Mode from Dv_topic where boardID=@boardid and istop = 0 and mode=@topicmode ORDER BY lastposttime desc
end
else
begin
set rowcount @pagesize
select TopicID,boardid,title,postusername,postuserid,dateandtime,child,hits,votetotal,lastpost,lastposttime,istop,isvote,isbest,locktopic,Expression,TopicMode,Mode from Dv_topic where boardID=@boardid and istop = 0 ORDER BY lastposttime desc
end
================================
ALTER PROCEDURE dv_toplist
@pagenow int ,
@pagesize int ,
@reture_value int output,
@intUserRecordCount int output
as
/*定义局部变量*/
declare @intBeginID int
declare @intEndID int
declare @intPageCount int
declare @intRowCount int
/*关闭计数*/
set nocount on
/*求总用户数*/
select @intUserRecordCount = count(*) from [dv_user]
if (@intUserRecordCount = 0) --如果没有用户,则返回零
set @reture_value =0
/*判断页数是否正确*/
if (@pagenow - 1) * @pagesize > @intUserRecordCount
set @reture_value =1
--return (-1)
/*求开始userID*/
set @intRowCount = (@pagenow - 1) * @pagesize + 1
/*限制条数*/
set rowcount @intRowCount
select @intBeginID = userid from [dv_user] order by userid desc
/*结束userID*/
set @intRowCount = @pagenow * @pagesize
/*限制条数*/
set rowcount @intRowCount
select @intEndID = userid from [dv_user] order by userid desc
/*恢复系统变量*/
set rowcount 0
set nocount off
select username,useremail,userclass,UserIM,UserPost,JoinDate,userwealth,userid from [dv_user] where userid between @intEndID and @intBeginID order by userid desc
return(@@rowcount)
--select @@rowcount
<zbbs>
================================================
ALTER PROCEDURE zbbs_topic
@page_size int,
@page_now int,
@board int,
@rsc int output
AS
declare @intCount int
declare @lasttime datetime
declare @affrow int
SET NOCOUNT ON
select @intCount=count(*) from z_topic where board=@board and topicid=0
if not (@page_size*(@page_now)<@intCount)
set @page_now=@intCount/@page_size-1
if @intCount=0
begin
set @page_now=0
set @intCount=1
end
set @affrow= @page_now*@page_size+1
set rowcount @affrow
select @lasttime=lasttime from z_topic where board=@board and topicid=0 order by lasttime desc
set rowcount @page_size
select * from z_topic where board=@board and lasttime<=@lasttime and topicid=0 order by lasttime desc
set @rsc=@intCount
RETURN
================================================
ALTER PROCEDURE zbbs_topic2
@page_size int,
@page_now int,
@board int,
@rsc int output
AS
declare @intBeginID int
declare @intEndID int
declare @intRowCount int
declare @intCount int
SET NOCOUNT ON
select @intCount=count(*) from z_topic where board=@board
if not (@page_size*(@page_now)<@intCount)
set @page_now=@intCount/@page_size-1
set @intRowCount=@page_now*@page_size+1
set rowcount @intRowCount
select @intBeginID = id from z_topic where board=@board order by id desc
set @intRowCount=(@page_now+1)*@page_size
set rowcount @intRowCount
select @intEndID=id from z_topic where board=@board order by id desc
set rowcount 0
set nocount off
select * from z_topic where board=@board and (id between @intEndID and @intBeginID) order by lasttime desc
set @rsc=@intCount
RETURN
================================
ALTER PROCEDURE dv_list
@boardid int=1,
@pagenow int=1, --当前页数
@pagesize int=1, --定义每页面帖子数目
@tl int=0, --按时间段查询
@topicmode int=0, --专题
@totalrec int output
AS
set nocount on
declare @int_topnum int
declare @int_timenum int
declare @var_times varchar(5000)
if @pagenow>1
if @topicmode>0
begin
select @int_timenum=(@pagenow-1)*@pagesize
set rowcount @int_timenum
select @var_times=lastposttime from Dv_Topic where boardID=@boardID and istop = 0 and mode=@topicmode ORDER BY lastposttime desc
set rowcount @pagesize
select TopicID,boardid,title,postusername,postuserid,dateandtime,child,hits,votetotal,lastpost,lastposttime,istop,isvote,isbest,locktopic,Expression,TopicMode,Mode from dv_topic where boardID=@boardID and istop = 0 and mode=@topicmode and lastposttime < @var_times ORDER BY lastposttime desc
set nocount off
return
end
else
begin
select @int_timenum=(@pagenow-1)*@pagesize
set rowcount @int_timenum
select @var_times=lastposttime from Dv_Topic where boardID=@boardID and istop = 0 ORDER BY lastposttime desc
set rowcount @pagesize
select TopicID,boardid,title,postusername,postuserid,dateandtime,child,hits,votetotal,lastpost,lastposttime,istop,isvote,isbest,locktopic,Expression,TopicMode,Mode from dv_topic where boardID=@boardID and istop = 0 and lastposttime < @var_times ORDER BY lastposttime desc
set nocount off
return
end
else
if @topicmode>0
begin
set rowcount @pagesize
select TopicID,boardid,title,postusername,postuserid,dateandtime,child,hits,votetotal,lastpost,lastposttime,istop,isvote,isbest,locktopic,Expression,TopicMode,Mode from Dv_topic where boardID=@boardid and istop = 0 and mode=@topicmode ORDER BY lastposttime desc
end
else
begin
set rowcount @pagesize
select TopicID,boardid,title,postusername,postuserid,dateandtime,child,hits,votetotal,lastpost,lastposttime,istop,isvote,isbest,locktopic,Expression,TopicMode,Mode from Dv_topic where boardID=@boardid and istop = 0 ORDER BY lastposttime desc
end
================================
ALTER PROCEDURE dv_toplist
@pagenow int ,
@pagesize int ,
@reture_value int output,
@intUserRecordCount int output
as
/*定义局部变量*/
declare @intBeginID int
declare @intEndID int
declare @intPageCount int
declare @intRowCount int
/*关闭计数*/
set nocount on
/*求总用户数*/
select @intUserRecordCount = count(*) from [dv_user]
if (@intUserRecordCount = 0) --如果没有用户,则返回零
set @reture_value =0
/*判断页数是否正确*/
if (@pagenow - 1) * @pagesize > @intUserRecordCount
set @reture_value =1
--return (-1)
/*求开始userID*/
set @intRowCount = (@pagenow - 1) * @pagesize + 1
/*限制条数*/
set rowcount @intRowCount
select @intBeginID = userid from [dv_user] order by userid desc
/*结束userID*/
set @intRowCount = @pagenow * @pagesize
/*限制条数*/
set rowcount @intRowCount
select @intEndID = userid from [dv_user] order by userid desc
/*恢复系统变量*/
set rowcount 0
set nocount off
select username,useremail,userclass,UserIM,UserPost,JoinDate,userwealth,userid from [dv_user] where userid between @intEndID and @intBeginID order by userid desc
return(@@rowcount)
--select @@rowcount
<zbbs>
================================================
ALTER PROCEDURE zbbs_topic
@page_size int,
@page_now int,
@board int,
@rsc int output
AS
declare @intCount int
declare @lasttime datetime
declare @affrow int
SET NOCOUNT ON
select @intCount=count(*) from z_topic where board=@board and topicid=0
if not (@page_size*(@page_now)<@intCount)
set @page_now=@intCount/@page_size-1
if @intCount=0
begin
set @page_now=0
set @intCount=1
end
set @affrow= @page_now*@page_size+1
set rowcount @affrow
select @lasttime=lasttime from z_topic where board=@board and topicid=0 order by lasttime desc
set rowcount @page_size
select * from z_topic where board=@board and lasttime<=@lasttime and topicid=0 order by lasttime desc
set @rsc=@intCount
RETURN
================================================
ALTER PROCEDURE zbbs_topic2
@page_size int,
@page_now int,
@board int,
@rsc int output
AS
declare @intBeginID int
declare @intEndID int
declare @intRowCount int
declare @intCount int
SET NOCOUNT ON
select @intCount=count(*) from z_topic where board=@board
if not (@page_size*(@page_now)<@intCount)
set @page_now=@intCount/@page_size-1
set @intRowCount=@page_now*@page_size+1
set rowcount @intRowCount
select @intBeginID = id from z_topic where board=@board order by id desc
set @intRowCount=(@page_now+1)*@page_size
set rowcount @intRowCount
select @intEndID=id from z_topic where board=@board order by id desc
set rowcount 0
set nocount off
select * from z_topic where board=@board and (id between @intEndID and @intBeginID) order by lasttime desc
set @rsc=@intCount
RETURN
相关文章推荐
- 学习存储过程的时候参看的两个DVBBS的存储过程和两个初步了解后自己写的存储过程(带分页的)
- mysql存储过程学习及java调用存储过程
- mssql 存储过程学习中 [5] 记录集分页
- 一个分页存储过程的学习
- 4000 oracle学习分页存储过程和jdbc调用
- 从通用分页存储过程[ROWCOUNT方式]抽出适合自己需求的分页过程
- {传智播客} (学习笔记)--Java调用存储过程实现Oracle数据库分页
- sql 学习之主键选择、简单分页存储过程
- 学习SQL SERVER的存储过程-之一认识存储过程语法
- mysql存储过程学习及java调用存储过程
- 存储过程:当基站ID大于1000的时候,把ID通过存储过程插入表,然后处理
- 毫秒级百万数据分页存储过程[供学习用]
- 自己收集比较强大的分页存储过程 推荐
- 学习SQL SERVER的存储过程----之一认识存储过程语法
- 对特定表进行分页显示的存储过程(要求有两个参数一个是 每页显示的记录的条数(@pagesize),第二个是显示第几页(@pageIndex))
- 自己写的带分页的存储过程
- 自己收集比较强大的分页存储过程 推荐
- 黑马程序员_学习日记72_724ASP.NET(ViewState、Cookie、Session、登录、分页存储过程)
- 以前自己写的一个分页的存储过程
- mysql存储过程学习及java调用存储过程