create procedure pagetest --用于翻頁的測試
--需要把排序字段放在第一列
(
@firstid nvarchar(20)=null, --當(dāng)前頁面里的第一條記錄的排序字段的值
@lastid nvarchar(20)=null, --當(dāng)前頁面里的最后一條記錄的排序字段的值
@isnext bit=null, --true 1 :下一頁;false 0:上一頁
@allcount int output, --返回總記錄數(shù)
@pagesize int output, --返回一頁的記錄數(shù)
@curpage int --頁號(第幾頁)0:第一頁;-1最后一頁。
)
as
if @curpage=0
begin
--統(tǒng)計總記錄數(shù)
select @allcount=count(productid) from product_test
set @pagesize=10
--返回第一頁的數(shù)據(jù)
select top 10
productid,
productname,
introduction
from product_test order by productid
end
else if @curpage=-1
select * from
(select top 10 productid,
productname,
introduction
from product_test order by productid desc ) as aa
order by productid
else
begin
if @isnext=1
--翻到下一頁
select top 10 productid,
productname,
introduction
from product_test where productid > @lastid order by productid
else
--翻到上一頁
select * from
(select top 10 productid,
productname,
introduction
from product_test where productid < @firstid order by productid desc) as bb order by productid
end
百萬數(shù)據(jù)翻頁就像100條數(shù)據(jù)一樣!
http://www.jyklzz.net/web/jyk/index.asp 這里有詳細(xì)的說明
菜鳥學(xué)堂:
新聞熱點
疑難解答
圖片精選