Two Methods of SQL Server paging:

Source: Internet
Author: User

The first method is the most traditional method. The variable in the stored procedure is used as the page multiplier.
Copy codeThe Code is as follows:
[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

-- Paging statement after SQL Server2005
Copy codeThe Code is as follows:
[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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.