| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 378 人关注过本帖
标题:b1分别复制到b2
只看楼主 加入收藏
yd1954
Rank: 2
来 自:辽宁沈阳
等 级:论坛游民
帖 子:153
专家分:21
注 册:2016-7-1
结帖率:100%
收藏
已结贴  问题点数:100 回复次数:11 
b1分别复制到b2
b1分别复制到b2

表名:b1,b2

将b1分三部分复制到b2.

1.将b1中的xh,qihao,h1,h2,h3字段,且h1=0的字段,复制到b2的相同字段中,也就是说,b1中的所有h1=0的那一行的xh,qihao,h1,h2,h3字段的内容复制到b2的相同字段。

2.将b1的h1=0的上一行的xh字段复制到b2的xh2字段中,放在与1.复制xh的同一行。b2中的xh的值与xh2的值是:xh-1=xh2.且在同一行。

3.b1的其它字段(指的是b1中h1=0的上一行的其它字段,不是h1=0的其它字段,且不包括qihao,h1,h2,h3)的内容,复制到b2的相同字段中,放在xh2的同一行。

注意:第一行h1=0,它的上一行不存在,可忽略。

程序运行后,
b2中的h1的值全都0,:
b2中的xh的值与xh2的值是:xh-1=xh2.且在同一行。
b1中的其它字段复制到b2的相同字段。
b1.zip (333.63 KB)

b2.zip (753 Bytes)
搜索更多相关主题的帖子: 相同 一行 字段 复制 内容 
2025-05-03 10:33
csyx
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:火星
等 级:版主
威 望:37
帖 子:795
专家分:3180
注 册:2018-3-13
收藏
得分:50 
程序代码:
Close Databases 
Use b1 In 0
Use b2 In 0 Exclusive
Zap in b2

Insert into b2 (xh,qihao,h1,h2,h3,xh2) select xh,qihao,h1,h2,h3,xh-1 from b1 where h1 = 0

For ii = 1 to AFields(aFlds, 'b1')
    cc = aFlds[ii,1]
    If !(','+Lower(cc)+',' $ ',xh,qihao,h1,h2,h3,xh2,')
        Update b2 set b2.&cc = b1.&cc from b2 inner join b1 on b2.xh2 == b1.xh
    EndIf
EndFor

这家伙很懒,啥也没留下
2025-05-03 11:27
csyx
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:火星
等 级:版主
威 望:37
帖 子:795
专家分:3180
注 册:2018-3-13
收藏
得分:0 
或者这样,执行效率更高些
程序代码:
Close Databases 
Use b1 In 0
Use b2 In 0 Exclusive

Select b1.*, b1.xh as xh2 from b1 inner join (select xh from b1 where h1 == 0) b3 on b1.xh == b3.xh-1 into cursor temp
Select b2
Zap
Append From Dbf('temp')
Use in temp
Update b2 set b2.xh = b1.xh, b2.qihao = b1.qihao, b2.h1 = b1.h1, b2.h2 = b1.h2, b2.h3 = b1.h3 from b2 inner join b1 on b2.xh2 == b1.xh-1




[此贴子已经被作者于2025-5-3 14:36编辑过]


这家伙很懒,啥也没留下
2025-05-03 14:31
schtg
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:Usa
等 级:贵宾
威 望:67
帖 子:2045
专家分:4180
注 册:2012-2-29
收藏
得分:50 
回复 2楼 csyx
不知我的理解对否?
图片附件: 游客没有浏览图片的权限,请 登录注册

程序代码:
select * from b1 into cursor t2 readwrite 
alter table t2 drop column qihao
alter table t2 drop column h1
alter table t2 drop column h2
alter table t2 drop column h3
alter table t2 rename column xh to xh2
select xh,h1,h2,h3 from b1 where h1 = 0 into cursor t1
select t1.*,t2.* from t1 left join t2 on t1.xh - 1 = t2.xh2 into table b2
2025-05-03 14:40
yd1954
Rank: 2
来 自:辽宁沈阳
等 级:论坛游民
帖 子:153
专家分:21
注 册:2016-7-1
收藏
得分:0 
回复 3楼 csyx
非常感谢老师的帮助,
待下步运行并核实数据。
2025-05-03 16:18
yd1954
Rank: 2
来 自:辽宁沈阳
等 级:论坛游民
帖 子:153
专家分:21
注 册:2016-7-1
收藏
得分:0 
回复 4楼 schtg
感谢!感谢!
接下来是运行、核实数据。
2025-05-03 16:20
yd1954
Rank: 2
来 自:辽宁沈阳
等 级:论坛游民
帖 子:153
专家分:21
注 册:2016-7-1
收藏
得分:0 
回复 3楼 csyx
csyx老师你好!
非常感谢您昨天帮助写的代码。
第一段代码如下:
Close Databases
Use b1 In 0
Use b2 In 0 Exclusive
Zap in b2

Insert into b2 (xh,qihao,h1,h2,h3,xh2) select
xh,qihao,h1,h2,h3,xh-1 from b1 where h1 = 0

For ii = 1 to AFields(aFlds, 'b1')
    cc = aFlds[ii,1]
    If !(','+Lower(cc)+',' $
',xh,qihao,h1,h2,h3,xh2,')
        Update b2 set b2.&cc = b1.&cc from b2 inner
join b1 on b2.xh2 == b1.xh
    EndIf
EndFor

第一段代码运行后
“Insert into b2 (xh,qihao,h1,h2,h3,xh2) select
xh,qihao,h1,h2,h3,xh-1 from b1 where h1 = 0”
这句显示“语法错误”
“Update b2 set b2.&cc = b1.&cc from b2 inner join b1
on b2.xh2 == b1.xh”
这句显示“命令中有不能识别的短语或关键字”

----------------------------------------

第二段代码如下:
Close Databases
Use b1 In 0
Use b2 In 0 Exclusive

Select b1.*, b1.xh as xh2 from b1 inner join (select
xh from b1 where h1 == 0) b3 on b1.xh == b3.xh-1 into
cursor temp
Select b2
Zap
Append From Dbf('temp')
Use in temp
Update b2 set b2.xh = b1.xh, b2.qihao = b1.qihao,
b2.h1 = b1.h1, b2.h2 = b1.h2, b2.h3 = b1.h3 from b2
inner join b1 on b2.xh2 == b1.xh-1
第二段代码运行后,
“Select b1.*, b1.xh as xh2 from b1 inner join (select
xh from b1 where h1 == 0) b3 on b1.xh == b3.xh-1 into
cursor temp”
这句显示“语法错误”
“Append From Dbf('temp')”
这句显示“找不到别名”
“Use in temp”
这句显示“找不到别名”
“Update b2 set b2.xh = b1.xh, b2.qihao = b1.qihao,
b2.h1 = b1.h1, b2.h2 = b1.h2, b2.h3 = b1.h3 from b2
inner join b1 on b2.xh2 == b1.xh-1”
这句显示“命令中有不能识别的短语或关键字”

希望老师帮助解决上述二段代码的问题。谢谢!
2025-05-04 09:59
yd1954
Rank: 2
来 自:辽宁沈阳
等 级:论坛游民
帖 子:153
专家分:21
注 册:2016-7-1
收藏
得分:0 
回复 4楼 schtg
sehtg老师你好!
非常感谢您昨天帮助写的代码。
代码如下:
 clear all
 use b1 shared
use b2
select * from b1 into cursor t2 readwrite
alter table t2 drop column qihao
alter table t2 drop column h1
alter table t2 drop column h2
alter table t2 drop column h3
alter table t2 rename column xh to xh2
select xh,h1,h2,h3 from b1 where h1 = 0 into cursor t1
select t1.*,t2.* from t1 left join t2 on t1.xh - 1 =
t2.xh2 into table b2

我在前面加了三句。
代码运行后,
“select * from b1 into cursor t2 readwrite”
这句显示“命令中有不能识别的短语或关键字”

希望老师帮助解决上述代码的问题。谢谢!
2025-05-04 10:00
csyx
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:火星
等 级:版主
威 望:37
帖 子:795
专家分:3180
注 册:2018-3-13
收藏
得分:0 
以下是引用yd1954在2025-5-4 09:59:34的发言:
这句显示“语法错误”
这句显示“命令中有不能识别的短语或关键字”
这句显示“找不到别名”
这句显示“命令中有不能识别的短语或关键字”

亲测无误,难不成你用的不是 vfp9?
如果不是 vfp9 我就无能为力了,自从17年开始接触 vfp,就已经是 vfp9 了,之前版本有哪些限制恕我一无所知

这家伙很懒,啥也没留下
2025-05-04 10:53
yd1954
Rank: 2
来 自:辽宁沈阳
等 级:论坛游民
帖 子:153
专家分:21
注 册:2016-7-1
收藏
得分:0 
回复 9楼 csyx
老师你好!
我用的是VFP6.0版。论坛里的9,0安装了几次,都不成功。抱歉,
2025-05-04 11:03
快速回复:b1分别复制到b2
数据加载中...
 
   



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

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