在sql2005之前,习惯性建立虚拟表进行分页,随着sql2005新的功能函数
Row_Number() Over ( Order By Columnname Desc )
我们可以不使用临时表就能实现分页.比如
SELECT * FROM (SELECT *, ROW_NUMBER() OVER( ORDER BY [Name] DESC) AS RowNumber
FROM Sales.SalesTerritory) AS TmpTable WHERE RowNumber BETWEEN 3 AND 6
针对一些分页可能需求返回总记录
select count(*) from Sales.SalesTerritory
或 (此记录可能不准确)
select top 1 rows from sys.sysindexes where id=object_id('Sales.SalesTerritory ')