您的位置:首页 > 数据库

sql Server 05中利用ROW_NUMBER() 函数分页

2009-06-03 17:20 344 查看
with p as

(select ROW_NUMBER() over(order by MCI_ID ASC) as row,* from dbo.Map_CompanyInfo)
select * from p where row between 10 and 20

说明:ROW_NUMBER()产生编号,over()设置排序,查询结果重命名为p, 查询10-20条数据

根据此可写翻页存储过程

Create PROCEDURE Select_Info
@startIndex INT,
@pageSize INT
as
begin
with p as
(select ROW_NUMBER() over(order by MCI_ID ASC) as row,* from dbo.Map_CompanyInfo)
select * from p where row between @startIndex and @startIndex+@pageSize-1
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: