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