网(LieHuo.Net)教程 利用SQL2005的row_number()重新写了个自定义分页存储过程,以下是代码:
以下为引用的内容: --@Tablename 表名 --@Orderby 排序的字段名 --@Index 页码 --@Size 页大小 ALTER PROCEDURE uspPaging @Tablename varchar(20),@Orderby varchar(20),@Index int=1,@Size int=10 AS BEGIN DECLARE @sql VARCHAR(100) SET @sql='SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY '+@Orderby+') AS ID,* FROM '+@Tablename+') AS temp WHERE ID BETWEEN ('+CAST(@index AS VARCHAR(5))+'-1)*'+CAST(@size AS VARCHAR(5))+'+1 AND '+CAST(@index*@size AS VARCHAR(5)) EXEC(@sql) END 例子:Northwind数据库 EXEC uspPaging 'Products','ProductID',3,3 |