• SQL ROW_NUMBER() 通用分页存储过程


      
    --提取分页数据,返回总记录数  
    Create 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
    
    --提取总记录数  
    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+1  
    set @ENum = @PageNumber*@PageSize  
      if(@PageNumber>200 or @PageSize>200)
      begin 
    set @SqlString = substring(@SqlString,charindex('select',@SqlString)+6,len(@SqlString))  
    --set @SqlString = 'SELECT  *  FROM (SELECT ROW_NUMBER()  OVER  ( ORDER BY '+@SequenceField+' )  AS RowNumber121 ,'+@SqlString +' ) as pageinga123 WHERE RowNumber121 BETWEEN  '+convert(varchar(10),@BNum)+' AND '+convert(varchar(10),@ENum)+' ORDER BY RowNumber121 '  
    
    set @SqlString = 'SELECT  *  into #temp FROM ( SELECT ROW_NUMBER()  OVER  ( ORDER BY '+@SequenceField+' )  AS RowNumber121 ,'+@SqlString +' ) as pageinga123    '  
    set @SqlString=@SqlString+' CREATE INDEX mycolumn_index ON #temp (RowNumber121) '
    set @sql2='select *from #temp  WHERE RowNumber121 BETWEEN  '+convert(varchar(10),@BNum)+' AND '+convert(varchar(10),@ENum)+' ORDER BY RowNumber121  '
    SET @Sql1 = ISNULL(@Sql1,' ')+'  '+ @SqlString+@sql2
    --SET @Sql1 = ISNULL(@Sql1,' ')+'  '+ @SqlString
    exec(@Sql1)
    end
    else begin 
    set @SqlString = substring(@SqlString,charindex('select',@SqlString)+6,len(@SqlString))  
    
    set @SqlString = 'SELECT  *  FROM (SELECT ROW_NUMBER()  OVER  ( ORDER BY '+@SequenceField+' )  AS RowNumber121 ,'+@SqlString +' ) as pageinga123 WHERE RowNumber121 BETWEEN  '+convert(varchar(10),@BNum)+' AND '+convert(varchar(10),@ENum)+' ORDER BY RowNumber121 '  
    SET @Sql1 = ISNULL(@Sql1,' ')+'  '+ @SqlString
    exec(@Sql1)
     end
    
    end  
      
    

      

  • 相关阅读:
    美国队长
    weka数据预处理
    weka特征选择(IG、chi-square)
    生成arff文件,csv转为arff
    logistic regression的一些问题,不平衡数据,时间序列,求解惑
    Feature Scaling
    【转】机器学习问题方法总结
    Canopy算法聚类
    ROC曲线及AUC评价指标
    评估指标:准确率(Precision)、召回率(Recall)以及F值(F-Measure)
  • 原文地址:https://www.cnblogs.com/zhang9418hn/p/3670044.html
Copyright © 2020-2023  润新知