SQL Server实现分页的方式
2007-05-31 15:23:18 来源:WEB开发网2000:
首先获得所有的记录集合的存储过程:
create PROCEDURE [dbo].[P_GetOrderNumber]
AS
select count(orderid) from orders;----orders为表
RETURN
分页的存储过程
create procedure [dbo].[P_GetPagedOrders2000]
(@startIndex int, ---开始页数
@pageSize int----每一页显示的数目
)
as
set nocount on
declare @indextable table(id int identity(1,1),nid int) ----定义一个表变量
declare @PageUpperBound int
set @PageUpperBound=@startIndex+@pagesize-1
set rowcount @PageUpperBound
insert into @indextable(nid) select orderid from orders order by orderid desc
select O.orderid,O.orderdate,O.customerid,C.CompanyName,E.FirstName+' '+E.LastName as EmployeeName
from orders O
left outer join Customers C
on O.CustomerID=C.CustomerID
left outer join Employees E
on O.EmployeeID=E.EmployeeID
inner join @indextable t on
O.orderid=t.nid
where t.id between @startIndex and @PageUpperBound order by t.id ----实现分页的关键
set nocount off
2005:
create [dbo].[P_GetPagedOrders2005]
(@startIndex INT,
@pageSize INT
)
AS
begin
WITH orderList AS (
SELECT ROW_NUMBER() OVER (ORDER BY O.orderid DESC)AS Row, O.orderid,O.orderdate,O.customerid,C.CompanyName,E.FirstName+' '+E.LastName as EmployeeName
from orders O
left outer join Customers C
on O.CustomerID=C.CustomerID
left outer join Employees E
on O.EmployeeID=E.EmployeeID)
SELECT orderid,orderdate,customerid,companyName,employeeName
FROM orderlist
WHERE Row between @startIndex and @startIndex+@pageSize-1
end
- ››SQL Server 2008 R2 下如何清理数据库日志文件
- ››sqlite 存取中文的解决方法
- ››SQL2005、2008、2000 清空删除日志
- ››实现dedeCMS二级导航的简单方法
- ››实现discuz投票选项文字添加链接进入查看详情
- ››SQL Server 2005和SQL Server 2000数据的相互导入...
- ››sql server 2008 在安装了活动目录以后无法启动服...
- ››实现android socket 聊天与调试
- ››实现windows7系统3D切换页面的方法
- ››实现Windows7系统局域网发现共享
- ››实现Navicat for MySQL的替换功能方法
- ››实现Win 8系统F8进入安全模式的方法
更多精彩
赞助商链接