SQL Server Learning Notes paging stored procedure + call

Source: Internet
Author: User

1  Use [Database name]2 GO3 4 SETAnsi_nulls on5 GO6 7 SETQuoted_identifier on8 GO9 CREATE PROCEDURE [dbo].[Stored Procedure name]Ten     @pageIndex INT, One     @pageSize INT,     A     @totalCount INTOUTPUT -  as  - SETNOCOUNT on the  - DECLARE @PageStart INT - DECLARE @PageEnd   INT -  + SET @pageStart=(@pageIndex-1)*@pageSize - SET @pageEnd=@pageIndex*@pageSize + BEGIN  A     SELECT @totalCount=COUNT(1) from [dbo].[Table name] at     SELECT  -          [Id] - , Field 1 - , Field 2 -         ,.....         -      from  in(SELECT  -Row_number () Over(ORDER  byField name) asRowNumber, to              [Id] +,[Name] -,[Phone] the,[ Age] *,[Createtime]  $          from [dbo].[Table name]  with(NOLOCK)) as TempPanax Notoginseng     WHERE Temp. RowNumber>@PageStart  and Temp. RowNumber<@PageEnd -     ORDER  by Temp. CreatetimeDESC,Temp. Name the END +  A GO

How to call this stored procedure:

1  Use [Database name]2 GO3 DECLARE @totalResult INT4 EXEC [Stored Procedure name] 1,Ten,@totalResultOutput5 SELECT @totalResult

SQL Server Learning Notes paging stored procedure + call

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.