| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1879 人关注过本帖
标题:同名字段替换找不到列
只看楼主 加入收藏
fdqzy
Rank: 1
等 级:新手上路
帖 子:368
专家分:0
注 册:2016-8-15
结帖率:73.97%
收藏
已结贴  问题点数:20 回复次数:18 
同名字段替换找不到列
程序代码:
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","")
***b1、b2字段名同,但记录数不同
SeLe   b1
mcount=Afields(marray)

      FOR i=1 TO mcount
         UPDATE b1 SET b1.marray(i,1)=b2.marray(i,1) from b2 WHERE b1.jnh==b2.jnh  &&用b2替换b1相同字段
      ENDFOR

运行时提示:SQL找不到列
但单独测试又找得到字段名
不知问题在哪?
如果部分字段名相同,能否用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","")


[此贴子已经被作者于2020-10-22 18:16编辑过]

搜索更多相关主题的帖子: create 替换 values insert into 
2020-10-22 17:41
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9848
专家分:27241
注 册:2012-2-5
收藏
得分:10 
程序代码:
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,"","")
INDEX on jnh TAG aa
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","")
SET RELATION TO jnh INTO b1
SCAN 
    REPLACE m1 WITH b2.m1, m2 WITH b2.m2 IN b1
ENDSCAN 
SET RELATION TO
SELECT b1
SET ORDER TO 
BROWSE 

坚守VFP最后的阵地
2020-10-22 18:21
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9848
专家分:27241
注 册:2012-2-5
收藏
得分:0 
程序代码:
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,"","","","")
INDEX on jnh TAG aa
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","")
SET RELATION TO jnh INTO b1
SCAN 
    REPLACE m1 WITH b2.m1, m2 WITH b2.m2 IN b1
ENDSCAN 
SET RELATION TO
SELECT b1
SET ORDER TO 
BROWSE 

坚守VFP最后的阵地
2020-10-22 18:25
fdqzy
Rank: 1
等 级:新手上路
帖 子:368
专家分:0
注 册:2016-8-15
收藏
得分:0 
回复 3楼 sdta
辛苦版主!
能否在字段名用通用型?
上面的问题是替换字段太多,写代码麻烦,才提出此问题。
2020-10-22 18:45
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9848
专家分:27241
注 册:2012-2-5
收藏
得分:0 
解决问题要用实例
放上实际用表及要解决的问题

坚守VFP最后的阵地
2020-10-22 19:08
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10609
专家分:43210
注 册:2014-5-20
收藏
得分:10 
b1.marray(i,1) 这样表达字段名不可以的吧
字段名变动的,之前的贴也有提到:
https://bbs.bccn.net/thread-503305-1-1.html
变通一下就可以
2020-10-22 19:50
fdqzy
Rank: 1
等 级:新手上路
帖 子:368
专家分:0
注 册:2016-8-15
收藏
得分:0 
回复 6楼 吹水佬
程序代码:
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 b1
mcount=Afields(marray)
scan
      FOR i=2 TO mcount
         kk1='b1.'+marray(i,1)
         kk2='b2.'+marray(i,1)
              
         REPLACE (kk1) WITH EVALUATE(kk2) FOR b1.jnh==b2.jnh
      ENDFOR
endscan 


程序代码:
SELECT b1
mcount=Afields(marray)
      FOR i=2 TO mcount
         kk1='b1.'+marray(i,1)
         kk2='b2.'+marray(i,1)
              
         REPLACE (kk1) WITH EVALUATE(kk2) FOR b1.jnh==b2.jnh
      ENDFOR

只替换b2最后一个值

[此贴子已经被作者于2020-10-22 20:25编辑过]

2020-10-22 20:23
fdqzy
Rank: 1
等 级:新手上路
帖 子:368
专家分:0
注 册:2016-8-15
收藏
得分:0 
回复 6楼 吹水佬
还是7楼的问题

[此贴子已经被作者于2020-10-22 20:41编辑过]

2020-10-22 20:32
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10609
专家分:43210
注 册:2014-5-20
收藏
得分:0 
程序代码:
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
2020-10-22 21:07
fdqzy
Rank: 1
等 级:新手上路
帖 子:368
专家分:0
注 册:2016-8-15
收藏
得分:0 
第1个问题可以了
程序代码:
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 b1
mcount1=Afields(marray1)
SELECT b2
mcount2=Afields(marray2)
SELECT 1

      FOR i=2 TO mcount1
         kk1='b1.'+marray1(i,1)
         kk2='b2.'+marray2(i,1)
         UPDATE b1 SET &kk1=&kk2 from b2 WHERE b1.jnh==b2.jnh     
        
      ENDFOR
     
brow          


[此贴子已经被作者于2020-10-22 21:11编辑过]

2020-10-22 21:09
快速回复:同名字段替换找不到列
数据加载中...
 
   



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

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