Ver Mensaje Individual
  #3  
Antiguo 10-11-2005
Avatar de jachguate
jachguate jachguate is offline
Miembro
 
Registrado: may 2003
Ubicación: Guatemala
Posts: 6.254
Reputación: 27
jachguate Va por buen camino
en general, suponiendo que qc1 está asociado a bd1 y qc2 a bd2, y ambos tienen algo como
Código SQL [-]
select * from Socio order by codigo
, simplemente podría hacerse un recorrido de ambas tablas:

Código Delphi [-]
Procedure IgualaSocios;

  function siguientecodigo(cod : integer) : integer;
  begin
    //qsiguiente esta asociado a db2 y tiene algo como:
    //select min(codigo) from socio where codigo > :codigo
    qsiguiente.parambyname('codigo').AsInteger := cod;
    qsiguiente.open;
    try
      result := qsiguienteSIGUIENTE.AsInteger;
    finally
      qsiguiente.close;
    end;
  end;

begin
  //inserta en qc2 los que no estén de qc1
  qc1.first;
  while not qc1.eof do
  begin
    if not qc2.locate('codigo', qc1codigo.asinteger, []) then
    begin
      qc2.insert;
      qc2codigo.value := qc1codigo.value;
      //el resto de campos se copia igual
      qc2.post;
    end
    qc1.next;
  end;
  //borra de qc2 los que no esten en qc1
  qc2.first;
  while not qc2.eof do
  begin
    if not qc1.locate('codigo', qc2codigo.AsInteger, []) then
    begin
      CodigoBorrado := qc2Codigo.AsInteger;
      qc2.Delete;
      if not qc2.locate('codigo', siguientecodigo(CodigoBorrado), []) then
        qc2.Last; {no hay mas códigos}
    end;
  end;
end;

No es muy eficiente, pero si las tablas de socios no son grandes, funcionará aceptablemente bien.

Hasta luego.

__________________
Juan Antonio Castillo Hernández (jachguate)
Guía de Estilo | Etiqueta CODE | Búsca antes de preguntar | blog de jachguate
Responder Con Cita