SQL stored procedure data paging source code

Source: Internet
Author: User

Stored ProcedureSource code:

 1   Use   [  Adventureworks2008r2  ]  2   Go  3   4   /*  * *** Object: storedprocedure [DBO]. [proc_pagedata] script Date: 12/12/2012 17:15:37 *****  */  5   Set Ansi_nulls On  --  On comparison operators follow SQL-92 standards. The SQL-92 standard requires that the value be false when a null value is equal to (=) or not equal to (<>.  6   Go  7   8   Set Quoted_identifier On   --  On identifiers can be separated by double quotation marks,  9   Go  10   11   Create   Proc  [  DBO  ] . [  Proc_pagedata  ]  12   @ Pageindex   Int , --  Indicates the current page number.  13   @ Pagesize   Int , --  Number of records displayed per page  14  @ Pagecount   Int Output, --  Total number of pages, output parameters  15   @ Rowcount   Int Output --  Total number of records, output  16   As  17   Begin  18   Select   @ Rowcount  = Count ( * ) From Person. Address --  Obtain the total number of records  19   Select   @ Pagecount  =  Ceiling ( @ Rowcount  /  @ Pagesize ) --  Obtain the total number of pages  20  --  Ceiling () is an integer obtained by ceiling (3.2 ).  21   --  Start Paging  22   Select   *  From  23 ( Select Row_number () Over ( Order   By Addressid) As Num,*  From  Person. Address)  24    As  Tab_tmp  25   Where  26 Num > ( @ Pageindex  -  1 ) *  @ Pagesize   And Num<=  @ Pageindex  *  @ Pagesize  27   End   28   29   30   --  Simplest Paging  31    32   --  -- Page displays 5 records on each page. Page 4th (Records 16-20)  33   -- Select top 5 * From person. Address  34   --  Where addressid not in  35   --  (  36   --  Select top 15 addressid from person. Address order by addressid  37   --  )  38   --  Order by person. Address. addressid 39   40   Go 

Call the stored procedure.I do not know why the stored procedure name is always in a red Ripple. The system prompts that the process cannot be found, but it can be executed.

 1   Declare   @ Pagecount   Int ; --  Total number of pages  2   Declare   @ Rowcount   Int ; --  Total number of records 3   Exec DBO. proc_pagedata 2 , 5 , @ Pagecount Out, @ Rowcount  Out  4   5   --  Select @ pagecount as A, @ rowcount as B 

Output result:

 

 

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.