Stored Procedures for retrieving data by page in SQL Server

Source: Internet
Author: User
SQL Server APIs are not efficient. If you are interested, you can test it. Let me know by the way. Thank you ~

The name of this application is SP _, but the SQL Server APIs are all SP _ headers. It is said that this prefix will be first searched in the API, reducing the performance. If you want to go and do not want to open more letters, you can use XP. This stored procedure can be used together with the sequence class of the database issued yesterday.

Create   Procedure DBO. xp_getpage

(

@ SQL Varchar ( 1000 ),

@ Page Int   =   1 ,

@ Pagesize Int   =   20 ,

@ Needcount Bit   =   1

)

As

Set Nocount On

Declare @ P1 Int -- P1 is the cursor ID



Set @ Page = (@ Page - 1 ) * @ Pagesize +   1

Exec Sp_cursoropen @ P1 output, @ SQL

Exec Sp_cursorfetch @ P1, 16 , @ Page, @ pagesize

Exec Sp_cursorclose @ p1


-- The above is enough. The following code is used to count the total number of records.

Select @ rowcount



Go

You are welcome to criticize, correct, and discuss.

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.