--提取分页数据,返回总记录数 ALTER procedure [dbo].[sp_Common_GetDataPaging_ReturnDataCount] ( @SqlString varchar(max), --查询语句 @PageNumber int, --当前的页码 @PageSize int, --每页显示的数据量 @SequenceField varchar(100), --排序字段 @DataCount int out --总数据量 ) as begin DECLARE @SqlAll VARCHAR(MAX) DECLARE @Sql1 VARCHAR(MAX) SET @SqlAll= @SqlString IF(CHARINDEX(‘/*CreateSqlStringOut*/‘,@SqlAll)>0) BEGIN declare @Sql nvarchar(max) SET @Sql=replace(@SqlAll,‘/*CreateSqlStringOut*/‘,‘‘) +N‘ select @execusercreatesql = @sql2‘ declare @execusercreatesql varchar(max) exec sp_executesql @Sql,N‘@execusercreatesql varchar(max) out‘,@execusercreatesql out set @SqlString =@execusercreatesql END --提取总记录数 declare @Sqlcount nvarchar(max) set @Sqlcount = ISNULL(@Sql1,‘ ‘)+‘ ‘+N‘select @countNum = count(1) from (‘+@SqlString+‘) as aaaaaaaaa‘ exec sp_executesql @Sqlcount,N‘@countNum int out‘,@DataCount out declare @BNum int declare @ENum int declare @sql2 varchar(max) set @BNum = (@PageNumber-1)*@PageSize set @ENum = @PageNumber*@PageSize --IF(CHARINDEX(‘/*CreateSqlStringOut*/‘,@SqlAll)>0) --begin --SET @SqlString=replace(@SqlAll,‘/*CreateSqlStringOut*/‘,‘‘) --set @SqlString =‘ ‘+left(@SqlString,len(@SqlString)-1)+‘ order by ‘+@SequenceField+‘ offset ‘+convert(varchar(10),@BNum)+‘ row fetch next ‘+convert(varchar(10),@PageSize)+‘ rows only‘ +char(39) --exec(@sql2) -- end -- else begin set @SqlString =‘ ‘+@SqlString+‘ order by ‘+@SequenceField+‘ offset ‘+convert(varchar(10),@BNum)+‘ row fetch next ‘+convert(varchar(10),@PageSize)+‘ rows only‘ exec(@SqlString) --end end