CREATE PROCEDURE [dbo]. [Getdatabypager] ( --Take @startIndex INT from the first few data --The table @tableName VARCHAR for the page,--The number of strips @pageSize int=5 per fetch, --Condition @condition varchar (+) = ' 1=1 ', --by ID @key varchar () = ' id ') asbegin --through the main building exclusion method Do not need to sort DECLARE @TopCount INT --set @TopCount = (@pageIndex-1) * @pageSize DECLARE @SQL VARCHAR ( +) SET @SQL = ' Select TOP ' +convert (VARCHAR), @pagesize) + ' * from ' [email protected] + ' WHERE ' + @ condition+ ' and ' [email protected]+ ' Not in (+convert ( VARCHAR), @startIndex) [email protected]+ ' From ' [email protected]+ '); ' --Total number of bars returned SET @SQL [email protected]+ ' SELECT COUNT (*) from ' [Email protected]+ ' WHERE ' [email protected] --prin T (@SQL) EXEC (@SQL) END
How to sqlservr the paging stored procedure