Sql分页存储过程
Sql2012及以上版本的分页比较简单:
CREATE PROCEDURE usp_pagingin2012 @Start INT=0, @PageLimit INT=10 AS BEGIN SELECT * FROM 表名 ORDER BY 列名 OFFSET @Start ROW 开始位置 FETCH NEXT @PageLimit ROWS ONLY END
Sql2005-2008分页稍微复杂一点:
CREATE PROCEDURE usp_paging @PageNumber INT=1, @PageSize INT=10 AS BEGIN WITH ctepaging AS (SELECT *, Row_number() OVER(ORDER BY 列名) AS rownum FROM 表名) SELECT * FROM ctepaging WHERE rownum BETWEEN ( @PageNumber - 1 ) * @PageSize + 1 AND @PageNumber * @PageSize END