1。在sqlserver中建一个存储过程,代码如下:
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
create proc GetRows
@begin as int,
@end as int
as
begin
with result as
(
select row_number() over(order by book_id desc) as rowindex,book_name,price from book
)
select * from result where rowindex between @begin and @end
end
通过with as 以提高性能,配合AspnetPager控件来实现分页,适合sql2005。
在sql2000中可以这样写
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
create proc GetRows2
@begin as int,
@end as int
as
begin
declare @table as table (rowindex int identity(1,1),bookName varchar(50),price money)
insert into @table select book_name,price from book order by book_id
select * from @table where rowindex between @begin and @end
end