Paged SQL stored procedure algorithm

Source: Internet
Author: User

/****** Object:  StoredProcedure [dbo].[ Pro_pub_fenye]    Script date:08/04/2014 11:14:22 ******/set ansi_nulls ongoset quoted_identifier ONGO/*-- suchao--2014-04-27--find public methods */create PROCEDURE [dbo]. [Pro_pub_fenye]    @AsyncSql NVARCHAR (MAX), @PageIndex int, @PageSize int, @RecordCount int outputasbeginset NOCOUNT ondeclare @Sql NVARCHAR ( MAX)--Define SQL statement set @[email protected];    DECLARE @pagesql NVARCHAR (MAX) SET @pagesql = ' SELECT * FROM (' [email protected]+ ') as temp WHERE myrank  between ' + CAST ( (@PageIndex-1) * @PageSize +1 as NVARCHAR) + ' and ' +cast (@PageIndex * @PageSize as NVARCHAR) + ' EXEC sp_executesql   @pagesql-The Execute SQL statement returns the current page data declare @recount NVARCHAR (MAX) SET @recount = ' SELECT @RecordCount =count (1) from (' [email protected]+ ') as temp ' EXEC sp_executesql @recount, N ' @RecordCount int output ', @RecordCount output--Returns the number of affected rows    print @ Recordcountreturn @ @errorENDGO

Paging SQL stored procedure algorithm

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.