Two Methods for querying by page on SQL Server

Source: Internet
Author: User

Two Methods of SQL Server paging query Abstract: SQL Server paging query is frequently used. The following describes how to implement two methods of SQL Server paging query, if you are interested in this, take a look.


Two Methods of querying by page in SQL Server:

SQL Server paging query is frequently used. The following describes the implementation methods of two SQL Server paging queries. If you are interested in this, take a look.

Pagesize: number of records displayed per page

Cureentpage: Current page number

 
 
  1. select * from (   select TOP pagesize * FROM ( SELECT TOP pagesize*cureentpage   * from user_table   ORDER BY id ASC ) as aSysTable   ORDER BY id DESC ) as bSysTable   ORDER BY id ASC 

For example, you must select the 3,000th-page records in tbllendlist, with 100 records on each page.

----------

Method 1:

 
 
  1. ----------  
  2. select top 100 * from tbllendlist   
  3. where fldserialNo not in  
  4. (  
  5. select top 300100 fldserialNo from tbllendlist   
  6. order by fldserialNo  
  7. )  
  8. order by fldserialNo 

Method 2:

 
 
  1. ----------  
  2. SELECT TOP 100 *   
  3. FROM tbllendlist   
  4. WHERE (fldserialNo >   
  5. (SELECT MAX(fldserialNo)   
  6. FROM (SELECT TOP 300100 fldserialNo   
  7. FROM tbllendlist   
  8. ORDER BY fldserialNo) AS T))   
  9. ORDER BY fldserialNo 

Two Methods of querying by page in SQL Server:

Method 1: Fast execution speed!

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.