标题:asp.net几十万条以上的数据查询!如何高效率分页!
只看楼主
yukai621
Rank: 2
等 级:论坛游民
威 望:1
帖 子:27
专家分:71
注 册:2010-8-13
结帖率:71.43%
已结贴  问题点数:20 回复次数:4 
asp.net几十万条以上的数据查询!如何高效率分页!
几十万条以上的数据查询!如何高效率分页!
搜索更多相关主题的帖子: 高效率 asp 数据 查询 
2010-10-22 09:07
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2545
专家分:9359
注 册:2007-11-3
得分:4 
可以用分页存储过程
程序代码:
CREATE PROCEDURE [dbo].[ProcCustomPage]
    (
     @Table_Name varchar(5000),    --表名
     @Sign_Record varchar(50),     --主键
     @Filter_Condition varchar(1000),    --筛选条件,不带where
     @Page_Size int,     --页大小
     @Page_Index int,       --页索引      
   @TaxisField varchar(1000), --排序字段
     @Taxis_Sign int,     --排序方式 1为 DESC, 0为 ASC

 @Find_RecordList varchar(1000),   --查找的字段
     @Record_Count int     --总记录数
     )
     AS
      BEGIN
      DECLARE @Start_Number int
      DECLARE @End_Number int
      DECLARE @TopN_Number int
     DECLARE @sSQL varchar(8000)

 if(@Find_RecordList='')

 BEGIN

 SELECT @Find_RecordList='*'

 END
     SELECT @Start_Number =(@Page_Index-1) * @Page_Size
      IF @Start_Number<=0
     SElECT @Start_Number=0
      SELECT @End_Number=@Start_Number+@Page_Size
      IF @End_Number>@Record_Count
     SELECT @End_Number=@Record_Count
     SELECT @TopN_Number=@End_Number-@Start_Number
     IF @TopN_Number<=0
     SELECT @TopN_Number=0
      print @TopN_Number
     print @Start_Number
     print @End_Number
     print @Record_Count

 IF @TaxisField=''

 begin

 select @TaxisField=@Sign_Record

 end
     IF @Taxis_Sign=0
       BEGIN
         IF @Filter_Condition=''
         BEGIN
           SELECT @sSQL='SELECT '+@Find_RecordList+' FROM '+@Table_Name+'
           WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@TopN_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+'
            WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@End_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+'
          ORDER BY '+@TaxisField+') order by '+@TaxisField+' DESC)order by '+@TaxisField
         END
        ELSE
        BEGIN
        SELECT @sSQL='SELECT '+@Find_RecordList+' FROM '+@Table_Name+'
     WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@TopN_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+'
     WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@End_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+'
     WHERE '+@Filter_Condition+' ORDER BY '+@TaxisField+') and '+@Filter_Condition+' order by '+@TaxisField+' DESC) and '+@Filter_Condition+' order by '+@TaxisField
         END
      END
    ELSE
      BEGIN
      IF @Filter_Condition=''
        BEGIN
          SELECT @sSQL='SELECT '+@Find_RecordList+' FROM '+@Table_Name+'
     WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@TopN_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+'
     WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@End_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+'
     ORDER BY '+@TaxisField+' DESC) order by '+@TaxisField+')order by '+@TaxisField+' DESC'
     END
      ELSE
      BEGIN
        SELECT @sSQL='SELECT '+@Find_RecordList+' FROM '+@Table_Name+'
     WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@TopN_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+'
     WHERE '+@Sign_Record+' in (SELECT TOP '+CAST(@End_Number AS VARCHAR(10))+' '+@Sign_Record+' FROM '+@Table_Name+'
     WHERE '+@Filter_Condition+' ORDER BY '+@TaxisField+' DESC) and '+@Filter_Condition+' order by '+@TaxisField+') and '+@Filter_Condition+' order by '+@TaxisField+' DESC'
     END
      END
      EXEC (@sSQL)
      IF @@ERROR<>0
      RETURN -3
     RETURN 0
     END
    
     PRINT @sSQL

GO
自己一直用的分页存储过程 希望对楼主有帮助

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2010-10-22 09:15
筱晓绾
Rank: 10Rank: 10Rank: 10
来 自:湖南
等 级:贵宾
威 望:12
帖 子:512
专家分:1736
注 册:2010-9-1
得分:4 
存储过程很强大,值得引用!LS也很强大!
2010-10-22 11:30
gtbHypo
Rank: 1
等 级:新手上路
帖 子:8
专家分:7
注 册:2010-10-22
得分:4 
不错,用ROW_NUMBER()函数应该也可以。
2010-10-22 16:04
何事惊慌
Rank: 6Rank: 6
等 级:侠之大者
威 望:4
帖 子:220
专家分:499
注 册:2008-7-2
得分:0 
分页有好几种,貌似好像是那个Top的那种方式效率最高,楼主可以自己试试

QQ:860234001
编程交流群:236949758
2010-10-22 22:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-323621-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019821 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved