Ver Mensaje Individual
  #4  
Antiguo 24-03-2020
Avatar de kuan-yiu
[kuan-yiu] kuan-yiu is offline
Miembro Premium
 
Registrado: jun 2006
Ubicación: Galicia. España.
Posts: 1.017
Reputación: 22
kuan-yiu Va camino a la fama
Código Delphi [-]
   qInsertar:= TQuery.create(Application);
   with qInsertar do
   begin
      try
         close;
         SQL.Clear;
         DatabaseName := miBase;
         SQL.Add('Insert into '+tabla1+' (Id)');
         SQL.Add('Values (:id)');
         Prepare;
         tabla2.first;
         tabla3.first;
         //Si no están ordenadas tienes que tener dos bucles anidados. Si lo están vale algo así.
         while (not tabla2.eof)and(not tabla3.eof) do
         begin
            if (tabla2.FieldByName('CODIGO').AsInteger=tabla3.FieldByName('CODIGO').AsInteger) and
               (tabla2.FieldByName('NOMBRE').AsString=tabla3.FieldByName('NOMBRE').AsString) then
            begin
               Parambyname('id').AsInteger  := tabla2.FieldByName('CODIGO').AsInteger;
               ExecSQL;
               tabla2.next;
               tabla3.next;
            end
            else
            begin
            //Siguiente registro. Depende de la ordenación. Avanzando una u otra según cual sea menor o mayor.
            end;
        end;
      finally
         Free;
      end;
   end;
Responder Con Cita