Code
--@Tablename 表名
--@Orderby 排序的字段名
--@Index 页码
--@Size 页大小
ALTER PROCEDURE uspPaging @Tablename varchar(20),@Orderby varchar(20),@Index int=1,@Size int=10
AS
BEGIN
DECLARE @sql VARCHAR(500)
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
--@Tablename 表名
--@Orderby 排序的字段名
--@Index 页码
--@Size 页大小
ALTER PROCEDURE uspPaging @Tablename varchar(20),@Orderby varchar(20),@Index int=1,@Size int=10
AS
BEGIN
DECLARE @sql VARCHAR(500)
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