用delphi自带数据库,希望把从一张数据表中查到的整条数据插入到另一张数据表中

2025-01-04 20:09:46
推荐回答(2个)
回答1:

var
v1,v2,v3,v4,v5,v6,v7:string;
begin
v1:=Edit1.Text;//设置的查询条件,即id数据
v2:=Edit2.Text;//因为原表中缺少这两个数据,所以通过Edit输入
v3:=Edit3.Text;//同上
v6:='"';
v4:='insert into customer (name,sex,id,room,date1,leave1) select name,sex,id,room,date1,leave1 from orders where id ='+v6+v1+v6;
v5:='update customer set deposit ='+v6+v2+v6+' where id = '+v6+v1+v6;
v7:='update customer set Money1 ='+v6+v3+v6+' where id = '+v6+v1+v6+;
query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add(v4);
Query1.ExecSQL;
query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add(v5);
Query1.ExecSQL;
query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add(v7);
Query1.ExecSQL;
end;

回答2:

var
v1,v2,v3,v4,v5,v6,v7:string;
begin
v1:=Edit1.Text;//设置的查询条件,即id数据
v2:=Edit2.Text;//因为原表中缺少这两个数据,所以通过Edit输入
v3:=Edit3.Text;//同上
v6:='"';
v4:='insert into customer(name,sex,id,room,date1,leave1, deposit, money1)' +
' select name,sex,id,room,date1,leave1, ' + v6 + v2 + v6 + ' as deposit, ' +
v6 + v3 + v6 + ' as Money1 from orders where id ='+v6+v1+v6;
query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add(v4);
Query1.ExecSQL;
end;
注意:如果你的id是int型的则 后边为 where id ='+v1;