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

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
fdqzy
Rank: 1
等 级:新手上路
帖 子:368
专家分:0
注 册:2016-8-15
收藏
得分:0 
回复 3楼 sdta
辛苦版主!
能否在字段名用通用型?
上面的问题是替换字段太多,写代码麻烦,才提出此问题。
2020-10-22 18:45
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
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
fdqzy
Rank: 1
等 级:新手上路
帖 子:368
专家分:0
注 册:2016-8-15
收藏
得分:0 
1楼第2个问题不知怎么解决?
2020-10-22 21:18
fdqzy
Rank: 1
等 级:新手上路
帖 子:368
专家分:0
注 册:2016-8-15
收藏
得分:0 
回复 9楼 吹水佬
谢谢!
1楼弟2个问题如何解决?
2020-10-22 22:05
fdqzy
Rank: 1
等 级:新手上路
帖 子:368
专家分: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
等 级:新手上路
帖 子:368
专家分: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
fdqzy
Rank: 1
等 级:新手上路
帖 子:368
专家分: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
快速回复:同名字段替换找不到列
数据加载中...
 
   



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

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