| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1050 人关注过本帖
标题:帮忙优化代码
取消只看楼主 加入收藏
fdqzy
Rank: 1
等 级:新手上路
帖 子:368
专家分:0
注 册:2016-8-15
结帖率:73.97%
收藏
已结贴  问题点数:20 回复次数:1 
帮忙优化代码
对表中每个字段连续出现的值,依次斌顺序值:
程序代码:
create cursor b1 (jnh N(2),m1 c(3),m2 c(3),m3 c(3))
insert into b1 values (1,"M1","","M3")
insert into b1 values (2,"","M2","")
insert into b1 values (3,"M1","","M3")
insert into b1 values (4,"","M2","")
insert into b1 values (5,"M1","","M3")
insert into b1 values (6,"M1","","M3")
insert into b1 values (7,"M1","","")
insert into b1 values (8,"","M2","")
insert into b1 values (9,"M1","","M3")
insert into b1 values (10,"M1","","M3")
insert into b1 values (11,"M1","","M3")
insert into b1 values (12,"M1","","M3")
insert into b1 values (13,"M1","","")
insert into b1 values (14,"","M2","")


dxcount=Afields(dxarray)
For j=2 To dxcount

    Select b1
    Select jnh,&dxarray(j,1) From b1 Where Not !Empty(&dxarray(j,1)) Into Cursor ls
    nxs=Reccount()
    If nxs>0
        Dimension qs(nxs)
    Else
        Select ls
        Use
        Loop
    Endif
    For p=1 To nxs  &&存储某类qsz段
        Go p
        Store jnh To qs(p)
    Endfor
    Select ls
    Use

    Select b1
    Calculate Max(qs(nxs)) To qsmax
    For mm=1 To nxs
        If mm=1
            Set Filter To jnh<qs(mm) And !Empty(&dxarray(j,1))
        Endif
        If mm<>1

            Set Filter To jnh>qs(mm-1) And jnh<=qs(mm) And !Empty(&dxarray(j,1))

        Endif
        Count To jns
        Go top
For kk=1 To jns
        Replace &dxarray(j,1) With Alltrim(Str(kk)) 
Skip 
Endfor
    Endfor
    Set Filter To jnh>qsmax And !Empty(&dxarray(j,1))
    Count To jns

    Go top
For kk=1 To jns
    Replace &dxarray(j,1) With Alltrim(Str(kk))
Skip 
Endfor
Endfor
Select b1
Set Filter To

Brow

这段代码循环太多,对多字段、多记录运行太慢,能否优化一下,谢谢!
搜索更多相关主题的帖子: Select For values into insert 
2020-10-31 19:55
fdqzy
Rank: 1
等 级:新手上路
帖 子:368
专家分:0
注 册:2016-8-15
收藏
得分:0 
回复 2楼 sdta
谢谢,比以前快多了!
2020-10-31 21:38
快速回复:帮忙优化代码
数据加载中...
 
   



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

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