--使用存儲過程的數據分頁 --pageSize 一頁有多少條 --pageIndex 第幾頁 --totalCount 總共有多少條 --分頁的第一種方法 select top(10) * from Ams_Area where ar_id not in ( Select top(0) ar_id from Ams_Area order by ar_id ) order by ar_id --分頁的第二種方法 select * from ( select *,ROW_NUMBER() over(order by ar_id)as num from Ams_Area )as s where s.num between 0 and 10 --使用存儲過程的分頁方法 create proc GetPageDataBuilding @pageSize int,--一頁有多少條數據 @pageIndex int,--第幾頁 @totalCount int output --總共有多少條 as begin declare @str nvarchar(1000); set @str = ('select top('+CAST(@pageSize as nvarchar(32))+') * from Ams_Area where ar_id not in(Select top('+CAST(((@pageIndex-1)*@pageSize) as nvarchar(32))+') ar_id from Ams_Area order by ar_id) order by ar_id') print @str exec (@str) select @totalCount=Count(1) from Ams_Area end --第二個版本的分頁 create proc GetPageDataBuilding @pageSize int,--一頁內有多少條數據 @pageIndex int,--第幾頁 @totalCount int output --共有多少條數據 as begin declare @str nvarchar(1000) set @str = ('select * from ( select *,ROW_NUMBER() over(order by ar_id)as num from Ams_Area )as s where s.num between '+CAST((@pageIndex-1)*@pageSize as nvarchar(32))+' and '+CAST(@pageSize*@pageIndex as nvarchar(32))+'') print @str exec(@str) select @totalCount=COUNT(1) from Ams_Area end --執行上面分頁的存儲過程 declare @Count int exec GetPageDataBuilding 10,2,@Count output print @Count --刪除存儲過程 drop proc GetPageDataBuilding
使用到的數據庫地址:點擊下載??
下載的文件包括:
?
?
?
作者:郝喜路
出處:http://www.cnblogs.com/haoxilu/
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。
關注互聯網信息::新浪微博 騰訊微博