Paging Stored Procedure

Source: Internet
Author: User

Copy codeThe Code is as follows:
Create procedure sp_pageQuery

@ Sqlstr nvarchar (4000 ),
@ Page_index int,
@ Page_size int,
@ Rec_count int out --
As
Set nocount on
Declare @ cursor_id int
Declare @ rowcount int

Exec sp_cursoropen @ cursor_id output, @ sqlstr, @ scrolopt = 1, @ ccopt = 1, @ rowcount = @ rowcount output

Set @ rec_count = @ rowcount

Set @ page_index = (@ page_index-1) * @ page_size + 1

IF @ rec_count> 0
BEGIN
Exec sp_cursorfetch @ cursor_id, 16, @ page_index, @ page_size
END
ELSE
BEGIN
Select 'test' = 'null' Where 1 = 2
END

Exec sp_cursorclose @ cursor_id
Set nocount off
GO



Call
Copy codeThe Code is as follows:
Create PROCEDURE [dev]. [P_Mobile_Comment_Page]
@ Course_ware_id int,
@ RecCountPerPage int = 1,
@ PageIndex int = 1,
@ RecordCount int = 0 out
AS

DECLARE @ SQL nvarchar (4000)

SET @ SQL ="
Select seg_id, course_ware_id, subject, cust_name, content, create_date
FROM T_COURSEWARE_COMMENT
Where course_ware_id = "+ cast (@ course_ware_id as varchar (10) +"
Order by seg_id"
EXEC sp_Pagequery @ SQL, @ pageIndex, @ recCountPerPage, @ recordCount out

GO


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.