In use, already do not know the source, if there is infringement please tell me, I immediately deleted.
Use [Activaonlinesupport]GO/** * * * object:storedprocedure [dbo]. [Proce_pagechange] Script date:08/13/2014 13:45:17 * * * * **/SETAnsi_nulls onGOSETQuoted_identifier onGOALTER PROCEDURE [dbo].[Proce_pagechange]( @TableName varchar( -),--Table name @ReFieldsStr varchar( $)= '*',--Field name (All fields are *) @OrderString varchar( $),--sort fields (must! support multiple fields without order by) @WhereString varchar( -)=N"',--conditional statements (do not add where) @PageSize int,--how many records per page @PageIndex int = 1,--Specify the current page @TotalRecord intOutput--returns the total number of records) as BEGIN --processing start and end points Declare @StartRecord int; Declare @EndRecord int; Declare @TotalCountSql nvarchar( -); Declare @SqlString nvarchar( -); Set @StartRecord =(@PageIndex-1)*@PageSize + 1 Set @EndRecord = @StartRecord + @PageSize - 1 SET @TotalCountSql=N'Select @TotalRecord = count (*) from' + @TableName;--Total Record Count statement SET @SqlString =N'(select Row_number () over (order by'+ @OrderString +') as RowId,'+@ReFieldsStr+' from'+ @TableName;--Query Statements -- IF(@WhereString!= "' or @WhereString!=NULL) BEGIN SET @TotalCountSql=@TotalCountSql + 'where'+ @WhereString; SET @SqlString =@SqlString+ 'where'+ @WhereString; END --The first execution gets --IF (@TotalRecord is null) --BEGIN EXECsp_executesql@totalCountSqlN'@TotalRecord int out',@TotalRecordOutput--returns the total number of records --END ----execution of the subject sentence Set @SqlString ='SELECT * from' + @SqlString + ') as T where rowId between' + LTrim(Str(@StartRecord))+ ' and' + LTrim(Str(@EndRecord)); Exec(@SqlString) END