【急】关于if endif scan for endscan用法

zuiailiangjingru 2011-07-07 01:45:06
tb

bh tj shu
a h 0
b a 3
c a 4

sele tb
scan for shu>0
l_s=shu
seek tj
if found()
repl shu with shu+l_s
endif
endscan

这样写好像是死循环,该怎么写?

...全文
254 22 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
WWWWA 2011-07-08
  • 打赏
  • 举报
回复
只是用楼主给出的数据测试,如果 用多个TJ=h的记录,需要修改程序
jxjdzwang5555 2011-07-08
  • 打赏
  • 举报
回复
学习:
Use Dbf('tb') Again In 0 Alias tb0 &&在最小工作区中再打开表取别名为tb0
Select tb0 &&选择tb0
Scan for shu > 0 &&条件为shu > 0的循环开始
If Seek(tj, 'tb') &&在tb表中找tj,此处的tj我认为是tb0中的
Replace next 1 tb.yj with tb.yj + tb0.shu in tb&&这句我不理解,tb表中的记录指针怎么确定?
EndIf&&条件结束
EndScan&&循环结束
Use in tb0&&关闭tb0表
。。。。。。
USE r:\temp\ttp
a=0
DO whil !EOF()
IF shu>0
a=a+shu
ENDIF
SKIP
endd
LOCATE FOR shu=0
REPLACE shu WITH a
感觉wwwa老师的意思是所有shu=0的都用所有累加的a值替换?

楼主,您试了嘛?你的意思是什么?

jxjdzwang5555 2011-07-08
  • 打赏
  • 举报
回复
谢谢20楼版主老师的指教。
看不出来
Use Dbf('tb') Again In 0 Alias tb0
Select tb0
Scan for shu > 0
If Seek(tj, 'tb')
Replace next 1 tb.yj with tb.yj + tb0.shu in tb
EndIf
EndScan
Use in tb0

scan for shu > 0
gh = recno()
l_s = shu
seek tj
if found()
repl yj with yj + l_s
endif
goto gh
endscan
的区别?
zuiailiangjingru 2011-07-08
  • 打赏
  • 举报
回复
scan for shu > 0
gh = recno()
l_s = shu
seek tj
if found()
repl yj with yj + l_s
endif
goto gh
endscan

用这个成功了!
都市夜猫 2011-07-08
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 jxjdzwang5555 的回复:]
Replace next 1 tb.yj with tb.yj + tb0.shu in tb&&这句我不理解,tb表中的记录指针怎么确定?
[/Quote]
前一句: If Seek(tj, 'tb'),已将 tb 的记录指针定位到 bh 等于 tb0.tj 的记录上
WWWWA 2011-07-07
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 zuiailiangjingru 的回复:]
用循环语句该怎么写?
[/Quote]
USE r:\temp\ttp
a=0
DO whil !EOF()
IF shu>0
a=a+shu
ENDIF
SKIP
endd
LOCATE FOR shu=0
REPLACE shu WITH a
都市夜猫 2011-07-07
  • 打赏
  • 举报
回复
Use Dbf('tb') Again In 0 Alias tb0
Select tb0
Scan for shu > 0
If Seek(tj, 'tb')
Replace next 1 tb.yj with tb.yj + tb0.shu in tb
EndIf
EndScan
Use in tb0
zuiailiangjingru 2011-07-07
  • 打赏
  • 举报
回复

select tj,sum(shu)=yj into # from tb group by tj

update a set a.yj = b.yj from tb a,## b where a.bh=b.tj
zuiailiangjingru 2011-07-07
  • 打赏
  • 举报
回复
用循环语句该怎么写?
zuiailiangjingru 2011-07-07
  • 打赏
  • 举报
回复
tb中有BH tj shu yj

SQL语句 select tj,sum(shu)=yj into # from tb where tj='a'

update a set a.yj = b.yj from tb a,## b where a.bh=b.tj

WWWWA 2011-07-07
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 zuiailiangjingru 的回复:]
引用 8 楼 wwwwa 的回复:

SELECT SUM(a.shu) as ma FROM ttp a INNER JOIN (;
SELECT * FROM ttp WHERE tj='h') b ON ALLTRIM(b.bh)=a.tj INTO CURSOR dd
UPDATE ttp SET shu=dd.ma WHERE tj='h'


数据量大,这方法不适合!
……
[/Quote]
测试过没有?上传dbf
到www.access911.net/csdn
只要有问题的表、查询,用WINRAR压缩
 贴数据以供测试
jxjdzwang5555 2011-07-07
  • 打赏
  • 举报
回复
实在是搞不清楚seek的作用是什么?
sele tb
scan for shu>0
l_s=shu
repl yj with yj+l_s
endscan
“找到TJ 把本身的SHU加到TJ的yj上”,也不知道如何理解?
WWWWA 2011-07-07
  • 打赏
  • 举报
回复
呵呵,如果SQL语句不适合,循环更慢
zuiailiangjingru 2011-07-07
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wwwwa 的回复:]

SELECT SUM(a.shu) as ma FROM ttp a INNER JOIN (;
SELECT * FROM ttp WHERE tj='h') b ON ALLTRIM(b.bh)=a.tj INTO CURSOR dd
UPDATE ttp SET shu=dd.ma WHERE tj='h'
[/Quote]

数据量大,这方法不适合!
WWWWA 2011-07-07
  • 打赏
  • 举报
回复
SELECT SUM(a.shu) as ma FROM ttp a INNER JOIN (;
SELECT * FROM ttp WHERE tj='h') b ON ALLTRIM(b.bh)=a.tj INTO CURSOR dd
UPDATE ttp SET shu=dd.ma WHERE tj='h'
zuiailiangjingru 2011-07-07
  • 打赏
  • 举报
回复
sele 1
use &tb alias tb
index on bh tag rx_bh
set order to rx_bh

tb

bh tj shu yj
a h 0 0
b a 3 0
c a 4 0

结果

bh tj shu yj
a h 0 7
b a 3 0
c a 4 0

找到TJ 把本身的SHU加到TJ的yj上
bojiansky 2011-07-07
  • 打赏
  • 举报
回复
world hello
都市夜猫 2011-07-07
  • 打赏
  • 举报
回复
直接贴源数据和想要得到的结果
统计前,表有没有设置活动索引(从你的代码上看应该有)?有的话是哪个字段?或者那些字段有索引?
lhwtouch 2011-07-07
  • 打赏
  • 举报
回复
hello world
  • 打赏
  • 举报
回复
hello world
加载更多回复(2)

662

社区成员

发帖
与我相关
我的任务
社区描述
提出问题
其他 技术论坛(原bbs)
社区管理员
  • community_281
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧