Create Procedure SP_Page @tb varchar (50), - Table name @col varchar (50), - Page @coltype int, - @ col column, 0- characters, 1-character type 2-date Time Type @ORDERBY BIT, - Sort, 0 - Order, 1-Reverse @Collist Varchar (800), - To query the list of fields, * Represents all field @PageSize Int, - per page record Number @Page Int, - Specify page @condition varchar (800), - Query Conditions @Pages Int Output - Total Page AS / * Function Description: Sub-query in the specified list, Page can be sequential, reverse query can specify page size, specify the query of any page, specify the list of output fields, return to the total number of pages: PBSQL version: 1.10 Last modified: 2004-11-29 * / declare @sql nvarchar (4000) , @ WHERE1 VARCHAR (800), @ WHERE2 VARCHAR (800) IF @Condition IS NULL OR RTRIM (@condition) = '' Begin - No Query Conditions Set @ WHERE1 = 'Where' set @ where2 = 'endelsebegin - Square condition set @ WHERE1 = 'Where (' @ condition ') and' - Conditions Condition plus this condition set @ where2 = 'where' @ conden - there is no condition and this condition endset @ SQL = 'SELECT @ Pages = CEILING ((*) 0.0) /' Cast (@Pagesize As Varchar) ') from' @ TB @ where2exec sp_executesql @ SQL, N '@ Pages Int Output', @ Pages Output - Computing Total IF @ Orderby = 0 Set @ SQL = 'SELECT TOP' CAS T (@PAGESIZE AS VARCHAR) '' @ Collist 'from' @ TB @ WHERE1 @ col '> (SELECT MAX (' @ col ')' 'from (SELECT TOP' CAST (@ PageSize * ( @ Page-1) As varchar) '' @ col 'from' @ TB @ WHERE2 'Order By' @ col '