Esto es un ejemplo.
Habría que :
- meter algunas cosas en un bloque try .. .except.
- hacer comprobaciones de que no haya fallado el abrir la base de datos
Podrías tomar el ejemplo y enviarle como parámetros, la tabla y la lista de los parámetros. Con esto generarías el select y el insert.
Código Delphi
[-]procedure TFMPrueba.Button1Click(Sender: TObject);
var
i : integer;
begin
with TOrigen do
begin
Database.Open;
Transaction.StartTransaction;
end;
with TDestino do
begin
Database.Open;
Transaction.StartTransaction;
end;
TOrigen.SQL.Text := 'Select campo1, compo2, campo3 from tabla where nuevo=1';
TDestino.SQL.Text := 'INSERT INTO tabla (campo1, compo2, campo3) VALUES (?campo1, ?compo2, ?campo3)';
TOrigen.ExecQuery;
while not TOrigen.EOF do
begin
for i := 0 to TDestino.Params.Count-1 do
begin
TDestino.Params[i].Assign(TOrigen.FieldByName[TDestino.Params[i].Name]);
end;
TDestino.ExecQuery;
end;
with TOrigen do
begin
TOrigen.Close;
Transaction.Commit;
Database.Open;
end;
with TDestino do
begin
TDestino.Close;
Transaction.Commit;
Database.Open;
end;
end;