很強的分頁預存程序,速度超快!

來源:互聯網
上載者:User

CREATE procedure  dbo.pager
(
--取得當前頁數
@pagenum int,
--取得每頁記錄數
@rowcount int,
--返回記錄總數
@count int output
)
 AS

--定義起始記錄ID
declare @start int
--定義結束記錄ID
declare @end int
--設定起始記錄ID,與當前頁數和每頁記錄數相關。
set @start=@pagenum*@rowcount
--設定結束記錄ID,與當前頁數和每頁記錄數相關,起始記錄ID減去每頁記錄數即為當前頁的記錄數。
set @end=@start-@rowcount
--設定選取記錄數
set rowcount @start
--將選取的記錄插入暫存資料表
select *  into #t1  from  myTable

--設定刪除的記錄數
set rowcount @end
--不是第一頁時刪除表,第一頁時不刪除表中資料。
if @end>0
--刪除暫存資料表中不必要的資料
delete #t1

--不限制選取的記錄數
set rowcount 0
--顯示暫存資料表中的資料
select * from #t1

--declare @count int
select @count=count(*)  from  myTable

GO

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.