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.