Use the largest and smallest IDs for paging

Source: Internet
Author: User
Tags define local

1 One BBS page:
2
3 If   Exists ( Select   *   From Sysobjects Where ID =   Object_id ( '''' Up_gettopiclist '''' ))
4 Drop   Proc Up_gettopiclist
5 Go
6
7 Create   Proc Up_gettopiclist
8 @ A_intforumid   Int ,
9 @ A_intpageno   Int ,
10 @ A_intpagesize   Int
11 As
12 /* Define local variables */
13 Declare   @ Intbeginid   Int
14 Declare   @ Intendid   Int
15 Declare   @ Introotrecordcount   Int
16 Declare   @ Intpagecount   Int
17 Declare   @ Introwcount   Int
18 /* Disable counting */
19 Set Nocount On
20
21 /* Check whether this layout exists */
22 If   Not   Exists ( Select   *   From Forum Where ID =   @ A_intforumid )
23 Return ( - 1 )
24
25 /* Calculate the total number of root posts */
26 Select   @ Introotrecordcount   =   Count ( * ) From BBS Where Fatherid = 0   And Forumid = @ A_intforumid
27 If ( @ Introotrecordcount   =   0 ) -- If no post is added, zero is returned.
28 Return   0
29
30 /* Determine whether the page number is correct */
31 If ( @ A_intpageno   -   1 ) *   @ A_intpagesize   >   @ Introotrecordcount
32 Return ( - 1 )
33
34 /* Please start rootid */
35 Set   @ Introwcount   = ( @ A_intpageno   -   1 ) *   @ A_intpagesize   +   1
36 /* Limit */
37 Set   Rowcount   @ Introwcount
38 Select   @ Intbeginid   = Rootid From BBS Where Fatherid = 0   And Forumid = @ A_intforumid
39 Order   By ID Desc
40
41 /* End the rootid */
42 Set   @ Introwcount   =   @ A_intpageno   *   @ A_intpagesize
43 /* Limit */
44 Set   Rowcount   @ Introwcount
45 Select   @ Intendid   = Rootid From BBS Where Fatherid = 0   And Forumid = @ A_intforumid
46 Order   By ID Desc
47
48 /* Restore System Variables */
49 Set   Rowcount   0
50 Set Nocount Off
51
52 Select A. ID, A. layer, A. forumid, A. Subject, A. faceid, A. Hits, A. Time, A. userid, A. fatherid,
53 A. rootid,
54 '''' Bytes ''''   =   Datalength (A. content), B. username, B. Email, B. homepage, B. Signature, B. Point
55 From BBS As A Join Bbsuser As B On A. userid = B. ID
56 Where Forumid = @ A_intforumid   And A. rootid Between   @ Intendid   And   @ Intbeginid
57 Order   By A. rootid Desc , A. ordernum Desc
58 Return ( @ Rowcount )
59 -- Select @ rowcount
60 Go

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.