The paging of the stored procedure!!

Source: Internet
Author: User
Tags define local rowcount
Stored Procedures | Paging CREATE proc Up_gettopiclist
@a_strForumID varchar (50),
@a_intPageNo int,
@a_intPageSize int
As
/* Define Local Variables * *
DECLARE @intBeginID int
DECLARE @intEndID int
DECLARE @intRootRecordCount int
DECLARE @intPageCount int
DECLARE @intRowCount int
/* Close Count * *
SET NOCOUNT ON


/* Ask for a total number of root paste * *
Select @intRootRecordCount = count (*) from Bbs_topic where Fatherid=0 and forumid= @a_strForumID
if (@intRootRecordCount = 0)--returns zero if no posts
return 0

* To determine whether the number of pages is correct *
if (@a_intPageNo-1) * @a_intPageSize > @intRootRecordCount
Return (-1)

* * Ask to start rootid*/
Set @intRowCount = (@a_intPageNo-1) * @a_intPageSize + 1
/* Limit number of bars * *
SET ROWCOUNT @intRowCount
Select @intBeginID = Rootid from bbs_topic where fatherid=0 and forumid= @a_strForumID
ORDER BY tid Desc

/* End rootid*/
Set @intRowCount = @a_intPageNo * @a_intPageSize
/* Limit number of bars * *
SET ROWCOUNT @intRowCount
Select @intEndID = Rootid from bbs_topic where fatherid=0 and forumid= @a_strForumID
ORDER BY tid Desc

/* RESTORE SYSTEM Variable * *
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

How to operate is not pasted!! Take a good look, everybody.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.