SQL example of paged query through stored procedure

Source: Internet
Author: User

--person created: Zengfanlong--Creation time: the-7- - Ten:Wuyi: the--Note: According to the company shorthand code to obtain the current gas cylinder profile data to be synchronized (page get) ALTER PROCEDURE [Up_gasbottles_getsyncdata_bypage] (@CompanyAbbrCode NVARCHAR ( 255) ="', @LatastRowVersion_BigInt BigInt, @CurrentMaxRowVersion_BigInt BigInt, @StartPageIndex INT=0, @EndPageIndex INT=0, @TotalCount INT OUTPUT) As BEGIN--(1), define SQL query SELECT*into #tempTb from dbo. Gasbottles as GS with (NOLOCK) WHERE ISNULL (Gasbottleno,"') <>"'and REPLACE ((SUBSTRING (GS. Gasbottleno,1,5) ),'-',"') =@companyAbbrCode and (CAST ([RowVersion] as BIGINT)>@LatastRowVersion_BigInt and CAST ([RowVersion] as BigInt)<=@CurrentMaxRowVersion_BigInt) IF (@StartPageIndex<=0and @EndPageIndex<=0) BEGIN SELECT*From #tempTb--returns the total number of pages SET @TotalCount= (SELECT COUNT (1) from #tempTb) END ELSE BEGIN--paging Get Data SELECT row_number () over (ORDER by GETDATE ()) as'Row' ,                        *Into #tempAll from #tempTb SELECT*From #tempAll WHERE Row between @StartPageIndex and @EndPageIndex TRUNCATE table #tempAll DROP table #tempAll END--Delete history table TRUNCATE table #tempTb DROP table #tempTb Endgo

SQL example of paged query through stored procedure

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.