标题:同名字段替换找不到列
只看楼主
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
1楼第2个问题不知怎么解决?
2020-10-22 21:18
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
回复 9楼 吹水佬
谢谢!
1楼弟2个问题如何解决?
2020-10-22 22:05
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
回复 12楼 fdqzy
字段名可以不相同
kk1取b1的字段名
kk2取b2的字段名
2020-10-22 22:11
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
以下是引用吹水佬在2020-10-22 22:11:48的发言:

字段名可以不相同
kk1取b1的字段名
kk2取b2的字段名

1楼第2个问题是:
b1和b2的字段数不同,但关键字和部分字段名相同,在b1中寻找与b2相同的字段名,用b2替换b1字段名相同的字段值。
2020-10-22 22:53
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
以下是引用吹水佬在2020-10-22 21:07:51的发言:

create cursor b1 (jnh N(2),m1 c(3),m2 c(3))
insert into b1 values (1,"","")
insert into b1 values (2,"","")
insert into b1 values (3,"","")
insert into b1 values (4,"","")
insert into b1 values (5,"","")

create cursor b2 (jnh N(2),m1 c(3),m2 c(3))
insert into b2 values (1,'M1',"")
insert into b2 values (3,"M1","M2")
insert into b2 values (4,"M1","")

SELECT b2
INDEX on jnh TAG jnh

SELECT b1
nCount = FCOUNT()
SET RELATION TO jnh INTO "b2"
SCAN
    IF FOUND("b2")
        FOR i=2 TO nCount
            kk1='b1.'+FIELD(i)
            kk2='b2.'+FIELD(i)
            REPLACE (kk1) WITH EVALUATE(kk2)
        ENDFOR
    ENDIF
ENDSCAN
SET RELATION TO
BROWSE

    这个问题解决了字段名不同、相同字段序数相同问题。
    但字段序数不同的同名字段如何解决(1楼的第2个问题)?
主要是如何比较两表动态字段相同的问题。
故请教!

[此贴子已经被作者于2020-10-23 09:37编辑过]

2020-10-23 09:14
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:323
帖 子:9621
专家分:26174
注 册:2012-2-5
得分:0 
以下是引用fdqzy在2020-10-23 09:14:27的发言:


这个问题解决了字段名不同、相同字段序数相同问题。
但字段序数不同的同名字段如何解决?
    以上问题的提出是:在一个表中提取部分数据再进行其他统计(原表某些字段未统计),统计后将新的结果替换原表未统计的字段,
因替换字段有点多,一个一个写替换代码,有点麻烦,故想能否用这种办法解决。后一个问题用得有点多,我未找到解决的方法,主要是如何比较两表动态字段相同的问题。
故请教!

3楼的代码看了吗

坚守VFP最后的阵地
2020-10-23 09:36
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
以下是引用fdqzy在2020-10-22 17:41:32的发言:

如果部分字段名相同,能否用b2替换b1同名字段值?
如:
create cursor b1 (jnh N(2),,m0 c(3),m1 c(3),m2 c(3),m3 c(3),)
insert into b1 values (1,"","","","")
insert into b1 values (2,"","","","")
insert into b1 values (3,"","","","")
insert into b1 values (4,"","","","")
insert into b1 values (5,"","","","")

create cursor b2 (jnh N(2),m1 c(3),m2 c(3))
insert into b2 values (1,'M1',"")
insert into b2 values (3,"M1","M2")
insert into b2 values (4,"M1","")


程序代码:
create cursor b1 (jnh N(2),m0 c(3),m1 c(3),m2 c(3),m3 c(3))
insert into b1 values (1,"","","","")
insert into b1 values (2,"","","","")
insert into b1 values (3,"","","","")
insert into b1 values (4,"","","","")
insert into b1 values (5,"","","","")

create cursor b2 (jnh N(2),m1 c(3),m2 c(3))
insert into b2 values (1,'M1',"")
insert into b2 values (3,"M1","M2")
insert into b2 values (4,"M1","")

SELECT b2
INDEX on jnh TAG jnh

SELECT b1
SET RELATION TO jnh INTO "b2"
SCAN
    IF FOUND("b2")
        FOR i=2 TO FCOUNT("b2")
            cf = FIELD(i,"b2")
            IF !EMPTY(FIELD(cf,"b1"))
                kk1 = 'b1.' + cf
                kk2 = 'b2.' + cf
                REPLACE (kk1) WITH EVALUATE(kk2) IN "b1"
            ENDIF
        ENDFOR
    ENDIF
ENDSCAN
SET RELATION TO
BROWSE

2020-10-23 11:18
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
以下是引用吹水佬在2020-10-23 11:18:13的发言:



create cursor b1 (jnh N(2),m0 c(3),m1 c(3),m2 c(3),m3 c(3))
insert into b1 values (1,"","","","")
insert into b1 values (2,"","","","")
insert into b1 values (3,"","","","")
insert into b1 values (4,"","","","")
insert into b1 values (5,"","","","")

create cursor b2 (jnh N(2),m1 c(3),m2 c(3))
insert into b2 values (1,'M1',"")
insert into b2 values (3,"M1","M2")
insert into b2 values (4,"M1","")

SELECT b2
INDEX on jnh TAG jnh

SELECT b1
SET RELATION TO jnh INTO "b2"
SCAN
    IF FOUND("b2")
        FOR i=2 TO FCOUNT("b2")
            cf = FIELD(i,"b2")
            IF !EMPTY(FIELD(cf,"b1"))
                kk1 = 'b1.' + cf
                kk2 = 'b2.' + cf
                REPLACE (kk1) WITH EVALUATE(kk2) IN "b1"
            ENDIF
        ENDFOR
    ENDIF
ENDSCAN
SET RELATION TO
BROWSE

谢谢!
2020-10-23 14:24
fdqzy
Rank: 1
等 级:新手上路
帖 子:354
专家分:0
注 册:2016-8-15
得分:0 
以下是引用sdta在2020-10-23 09:36:48的发言:


3楼的代码看了吗

看了。
谢谢版主!
这个代码是对已知道字段名一一去写替换代码,当需要替换的字段名多了,写起来就有点烦锁,就想寻个方便的方法不一个一个去写替换代码。
2020-10-23 14:36



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




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

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