存储过程|分页create proc up_GetTopicList
a_strForumID varchar(50) ,
a_intPageNo int ,
a_intPageSize int
as
/*定义局部变量*/
declare intBeginID int
declare intEndID int
declare intRootRecordCount int
declare intPageCount int
declare intRowCount int
/*关闭计数*/
set nocount on
/*求总共根贴数*/
select intRootRecordCount = count(*) from bbs_topic where fatherid=0 and forumid=a_strForumID
if (intRootRecordCount = 0) --如果没有贴子,则返回零
return 0
/*判断页数是否正确*/
if (a_intPageNo - 1) * a_intPageSize > intRootRecordCount
return (-1)
/*求开始rootID*/
set intRowCount = (a_intPageNo - 1) * a_intPageSize + 1
/*限制条数*/
set rowcount intRowCount
select intBeginID = rootid from bbs_topic where fatherid=0 and forumid=a_strForumID
order by tid desc
/*结束rootID*/
set intRowCount = a_intPageNo * a_intPageSize
/*限制条数*/
set rowcount intRowCount
select intEndID = rootid from bbs_topic where fatherid=0 and forumid=a_strForumID
order by tid desc
/*恢复系统变量*/
set rowcount 0
set nocount off
select a.tid , a.layer , a.forumid , a.subject , a.faceid , a.hits , a.posttime , a.UserID , a.fatherid , a.rootid ,
'Bytes' = datalength(a.content) , b.loginname , b.Email , b.HomePage , b.Signature , b.Point
from bbs_topic as a join BBS_User as b on a.UserID = b.uid
where Forumid=a_strForumID and a.rootid between intEndID and intBeginID
order by a.rootid desc , a.ordernum desc
return(rowcount)
--select rowcount
go
怎么操作就不贴了!!大家好好看看,
存储过程的分页!!
80酷酷网 80kuku.com