Here is the creation of the stored procedure, which is called when it is used.
/** * * * object:storedprocedure [dbo]. [Sq_paging] Script date:09/10/2014 09:57:54 * * * * **/SETAnsi_nulls onGOSETQuoted_identifier onGOCREATE proc [dbo].[Yc_pageselect]@tbName varchar(255),--Table name@tbFields varchar( +),--return field@PageSize int,--Page Size@PageIndex int,--Page Number@strWhere varchar( +),--Query Criteria@StrOrder varchar(255),--Sorting Criteria@Key varchar( -)--Sort Fields asDeclare @strSql varchar( the)--subject SentenceDeclare @strSqlCount nvarchar( -)--Query the total number of records subject sentence--total number of records---------------------------if @strWhere !="'beginSet @strSqlCount='Select COUNT (*) as Totalcout from' + @tbName + 'where'+ @strWhereEndElsebeginSet @strSqlCount='Select COUNT (*) as Totalcout from' + @tbNameEnd--------------Paging------------if @PageIndex <= 1beginSet@strSql='Select Top'+Str(@PageSize)+' '+@tbFields+' from' + @tbName+ 'where' + @strWhere +' ' + @strOrderEndElsebeginSet @strSql='Select Top'+Str(@PageSize)+' '+@tbFields+' from' + @tbName + 'where' + @strWhere+' and'+@Key +'> (select MAX ('+@Key+') from (select Top'+Str((@PageIndex-1)*@PageSize)+' '+@Key +' from' + @tbName + 'where' + @strWhere +' '+@strOrder +') a)'+ @strOrderEndexec(@strSqlCount)exec(@strSql)GO
SQL Server SQL paging (for personal use)