A little bit of the online circulation of the general change, even the results of the table query can be returned
Create PROC [dbo]. [PageView] (@sql nvarchar (max),---original query Statement @pageindex int,--page number @pagesize int,--Number of records per page @sort VARCHAR (255),--sort fields and rules without order By@getcount bit--whether to get the total number of records 1 for the total number of records, 0 to not get the total number of records, return recordset) asdeclare @strSql nvarchar (max) set NOCOUNT on;if (@GetCount = 1) Beginset @strSql = ' Select COUNT (*) as GetRowCount from (' [E-mail protected]+ ') t ' endelsebeginset @strSql = ' select * FROM (S Elect Row_number () over (ORDER by ' + @Sort + ') as RowNum, * from (' [email protected]+ ') as Dwhere) Twhere T.rownum Betwe EN ' + CAST (((@PageIndex-1) * @PageSize + 1) as varchar (+) + ' and ' + CAST ((@PageIndex * @PageSize) as varchar ()) endexec (@strSql) set NOCOUNT off;
Take a look.
EXEC book.dbo.PageView ' select * from book where id<58385557 ',, ' id desc ', 1 exec book.dbo.PageView ' select * FROM Book where id<58385557 ',,, ' id desc ', 0
Results
SQL Server paging stored procedures