如何将一个表中的记录复制到别一个表中的相同字段中?(100分)

斌斌

Unregistered / Unconfirmed
GUEST, unregistred user!
如何将一个表中的记录复制到别一个表中的相同字段中?
原先使用BDE时,用一个语句就可以了(table2表中内容复制到table1表中):
table1.batchmove(table2.batappendupdate);
 
insert tablename1 (field1..fieldn)
select field1..fieldn
from tablename2
 
同意楼上,标准sql语法
 
我使用了如下,还是不对:
insert table1 (姓名,性别)
select 姓名,性别
from table2
求教!
 
insert table1 (姓名,性别)
(select 姓名,性别
from table2)
还有你的字段类型,长度是否一样?
 
字段一样的。
执行后返回“commandtext does not return a result set”错误,请问如何解决?
我是想先将表1清空,然后将表2中的所有与表1相同的字段记录复制到表1?请问谁有完整的办法,谢了!
 
呵呵,这个是个执行sql,不返回数据集的,直接execute
 
楼上说的都是对的了,你检查一下你的程序,如果真的不行的话,
用笨方法也行
with 第二个表的dataset do
begin
first;
while not eof do
begin
第一个表的dataset.fieldbyname('字段1').asstring:=fieldbyname('字段1').asstring
第一个表的dataset.fieldbyname('字段1').asstring:=fieldbyname('字段1').asstring
.......
end;
end;
如果记录不是很多的话,效率还是可以的
 
如果是ACCESS必须是Insert into table1 (姓名,性别)
select 姓名,性别
from table2
如果不行,这样试试。

Insert into table1 (姓名,性别)
(select 姓名,性别
from table2) A
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
987
SUNSTONE的Delphi笔记
S
S
回复
0
查看
805
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
958
SUNSTONE的Delphi笔记
S
顶部