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: