sqlserver分頁的兩種寫法分別介紹
更新時間:2012年11月23日 09:07:28 作者:
本文將介紹sql server傳統(tǒng)的寫法與SQL Server2005以后的分頁語句需要了解的朋友可以參考下
第一種是最傳統(tǒng)的寫法,用存儲過程中的變量作為分頁的乘數
[c-sharp] view plaincopyprint?create proc p_paged1
@pageSize int,@currentPage int
as
select top (@pageSize) * from student
where id not in
(select top (@pageSize*(@currentPage-1)) id from student)
go
exec p_paged1 2,3
create proc p_paged1
@pageSize int,@currentPage int
as
select top (@pageSize) * from student
where id not in
(select top (@pageSize*(@currentPage-1)) id from student)
go
exec p_paged1 2,3
--SQL Server2005以后的分頁語句
[c-sharp] view plaincopyprint?create proc p_paged2
@pageStart int, @pageEnd int
as
select * from
(select *,row_number() over(order by id desc) as rnum
from student) t
where t.rnum between @pageStart and @pageEnd
go
exec p_paged2 5,10
復制代碼 代碼如下:
[c-sharp] view plaincopyprint?create proc p_paged1
@pageSize int,@currentPage int
as
select top (@pageSize) * from student
where id not in
(select top (@pageSize*(@currentPage-1)) id from student)
go
exec p_paged1 2,3
create proc p_paged1
@pageSize int,@currentPage int
as
select top (@pageSize) * from student
where id not in
(select top (@pageSize*(@currentPage-1)) id from student)
go
exec p_paged1 2,3
--SQL Server2005以后的分頁語句
復制代碼 代碼如下:
[c-sharp] view plaincopyprint?create proc p_paged2
@pageStart int, @pageEnd int
as
select * from
(select *,row_number() over(order by id desc) as rnum
from student) t
where t.rnum between @pageStart and @pageEnd
go
exec p_paged2 5,10
相關文章
mybatis collection 多條件查詢的實現(xiàn)方法
這篇文章主要介紹了mybatis collection 多條件查詢的實現(xiàn)方法的相關資料,希望通過本文能幫助到大家,需要的朋友可以參考下2017-10-10SQL Server 2005 數據庫轉 SQL Server 2000的方法小結
這篇文章主要介紹了SQL Server 2005 數據庫轉 SQL Server 2000的方法,需要的朋友可以參考下2014-04-04SQL Server 2012無法連接到WMI提供程序(Cannot connect to WMI provider)解
這篇文章主要介紹了SQL Server 2012無法連接到WMI提供程序(Cannot connect to WMI provider)解決方案,需要的朋友可以參考下2014-07-07SQL中concat、concat_ws()、group_concat()的使用與區(qū)別
本文主要介紹了SQL中concat、concat_ws()、group_concat()的使用與區(qū)別,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-05-05SQL Server Parameter Sniffing及其改進方法
這篇文章主要介紹了SQL Server Parameter Sniffing及其改進方法,需要的朋友可以參考下2017-06-06SQL Server的通用分頁存儲過程 未使用游標,速度更快!
使用SQL Server時,分頁處理一直是個比較棘手的問題2010-11-11