Home >Database >Mysql Tutorial >sqlserver2000分页

sqlserver2000分页

WBOY
WBOYOriginal
2016-06-07 15:45:361274browse

DECLARE @PAGETEMP TABLE ( __ROW_NUM INT IDENTITY(1,1), __TID INT ) INSERT INTO @PAGETEMP(__TID) SELECT TOP 30 OrderID FROM dbo.Orders order by RequiredDate SELECT [@PAGETEMP].__ROW_NUM,* FROM Orders,@PAGETEMP WHERE dbo.Orders.OrderID= [@PA

DECLARE @PAGETEMP TABLE (

__ROW_NUM INT IDENTITY(1,1),

__TID INT

)

INSERT INTO @PAGETEMP(__TID) SELECT TOP 30 OrderID FROM dbo.Orders  order by RequiredDate

SELECT [@PAGETEMP].__ROW_NUM,* FROM Orders,@PAGETEMP WHERE dbo.Orders.OrderID= [@PAGETEMP].__TID AND [@PAGETEMP] .__ROW_NUM>20 AND [@PAGETEMP].__ROW_NUM

首先建立一个带自增字段的表变量 (__ROW_NUM) ,然后把对应分页表的主键插入该临时表 (__TID),这个临时表就把查询表的主键字段根据查询条件进行了重新的自增排序。那么下一步就是根据这个重新排序好的表变量进行与查询表关联。得到想返回的行数。表变量分页和05的分页方式很像。都是根据查询内容得到一个带有自增序号的临时表,然后得到需要的行数。

资料引用:http://www.knowsky.com/545707.html

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn