Use SQL statements for paging

Source: Internet
Author: User
Declare @ pagesize int -- number of records displayed on each page
Declare @ pages int -- number of pages to be displayed
Set @ pagesize = 5
Set @ pages = 2
Declare @ SQL nvarchar (200)
Set @ SQL = 'select top '+ STR (@ pagesize) +' * from (select top '+ STR (@ pagesize * @ pages)
+ '* From blog_config order by blogid ASC) as t order by blogid DESC'
Exec (@ SQL)

/*
Paging using SQL statements
The first step to use this technology is to multiply the number of pages required by the page size, sort the results in ascending order using the top keyword, and then embed this query into another query.
This query is the number of records that take the page size. Is a descending Processing
This query returns the last page of the embedded query. If necessary, the final query results can be processed in ascending order.
*/

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.