Fórum Comparação entre tabelas #337972
16/02/2007
0
Galera tenho esta procedure que faz comparação entre duas tabelas com comparação entre dois campos, agora preciso fazer o seguinte preciso que ela compare 03 campos, se algum dos 03 campo da tabela01 for diferente da tabela02 ele joga esse registro na tabela03.
aqui vai o codigo de como faço com um campo, mais naum to acertando por os 03.
procedure TForm1.Button1Click(Sender: TObject);
begin
ADOQuerysemvalor.First;
while (not ADOQuerysemvalor.Eof) do
begin
ADOQuerycomvalor.First;
while (not ADOQuerycomvalor.Eof) do
begin
if (ADOQuerysemvalor.FieldByName(´Inscricao´).Value = ADOQuerycomvalor.FieldByName(´Inscricao´).Value) then
begin
ADOQuerysemvalor.Edit;
ADOQuerysemvalor.FieldByName(´Valor´).Value := ADOQuerycomvalor.FieldByName(´Valor´).Value;
ADOQuerysemvalor.Post;
end;
ADOQuerycomvalor.Next;
end;
ADOQuerysemvalor.Next;
end;
end;
end.
aqui vai o codigo de como faço com um campo, mais naum to acertando por os 03.
procedure TForm1.Button1Click(Sender: TObject);
begin
ADOQuerysemvalor.First;
while (not ADOQuerysemvalor.Eof) do
begin
ADOQuerycomvalor.First;
while (not ADOQuerycomvalor.Eof) do
begin
if (ADOQuerysemvalor.FieldByName(´Inscricao´).Value = ADOQuerycomvalor.FieldByName(´Inscricao´).Value) then
begin
ADOQuerysemvalor.Edit;
ADOQuerysemvalor.FieldByName(´Valor´).Value := ADOQuerycomvalor.FieldByName(´Valor´).Value;
ADOQuerysemvalor.Post;
end;
ADOQuerycomvalor.Next;
end;
ADOQuerysemvalor.Next;
end;
end;
end.
Digital_man
Curtir tópico
+ 0
Responder
Posts
16/02/2007
Somar
Na tabela dois tbm são 3 campos , ou é 3 por 1 ou Vc quer comparar 3 por 3
pelo q entendi vc vai precisar fazer 3 ifs.
if TAB1.CAMPO1 = TAB2.CAMPO1 then
// codigo
if TAB1.CAMPO2 = TAB2.CAMPO1 then
// codigo
if TAB1.CAMPO3 = TAB2.CAMPO1 then
se for o segundo caso
isso vai triplicar
if TAB1.CAMPO1 = TAB2.CAMPO2 then
// codigo
if TAB1.CAMPO2 = TAB2.CAMPO2 then
// codigo
if TAB1.CAMPO3 = TAB2.CAMPO2 then
if TAB1.CAMPO1 = TAB2.CAMPO3 then
// codigo
if TAB1.CAMPO2 = TAB2.CAMPO3 then
// codigo
if TAB1.CAMPO3 = TAB2.CAMPO3 then
acho q é isso , embora naum tenha entendido muito bem o problema.
t+
pelo q entendi vc vai precisar fazer 3 ifs.
if TAB1.CAMPO1 = TAB2.CAMPO1 then
// codigo
if TAB1.CAMPO2 = TAB2.CAMPO1 then
// codigo
if TAB1.CAMPO3 = TAB2.CAMPO1 then
se for o segundo caso
isso vai triplicar
if TAB1.CAMPO1 = TAB2.CAMPO2 then
// codigo
if TAB1.CAMPO2 = TAB2.CAMPO2 then
// codigo
if TAB1.CAMPO3 = TAB2.CAMPO2 then
if TAB1.CAMPO1 = TAB2.CAMPO3 then
// codigo
if TAB1.CAMPO2 = TAB2.CAMPO3 then
// codigo
if TAB1.CAMPO3 = TAB2.CAMPO3 then
acho q é isso , embora naum tenha entendido muito bem o problema.
t+
Responder
Gostei + 0
16/02/2007
Digital_man
Oi amigo acho que expliquei mal né. E o seguinte vou por exemplo pra esclarecer.
Na tabela1 tenho.
Cadastro nome bairro
Na tabela2 tenho
Cadastro nome bairro
Os 3 da tabela1 tem que ser igual ao da tabela2 exatamente os 3
Se ele achar alguma diferença em qualquer um dos 3 campo ele pegara pegara os 3 campos da tabela q esta errada e jogara em outra tabela.
A tabela certa e a tabela1 se tiver alguma coisa errada em qualquer campo da tabela2 ele joga o registro com os 3 campos na tabela taberro.
Deu pra entender agora.
Na tabela1 tenho.
Cadastro nome bairro
Na tabela2 tenho
Cadastro nome bairro
Os 3 da tabela1 tem que ser igual ao da tabela2 exatamente os 3
Se ele achar alguma diferença em qualquer um dos 3 campo ele pegara pegara os 3 campos da tabela q esta errada e jogara em outra tabela.
A tabela certa e a tabela1 se tiver alguma coisa errada em qualquer campo da tabela2 ele joga o registro com os 3 campos na tabela taberro.
Deu pra entender agora.
Na tabela dois tbm são 3 campos , ou é 3 por 1 ou Vc quer comparar 3 por 3
pelo q entendi vc vai precisar fazer 3 ifs.
if TAB1.CAMPO1 = TAB2.CAMPO1 then
// codigo
if TAB1.CAMPO2 = TAB2.CAMPO1 then
// codigo
if TAB1.CAMPO3 = TAB2.CAMPO1 then
se for o segundo caso
isso vai triplicar
if TAB1.CAMPO1 = TAB2.CAMPO2 then
// codigo
if TAB1.CAMPO2 = TAB2.CAMPO2 then
// codigo
if TAB1.CAMPO3 = TAB2.CAMPO2 then
if TAB1.CAMPO1 = TAB2.CAMPO3 then
// codigo
if TAB1.CAMPO2 = TAB2.CAMPO3 then
// codigo
if TAB1.CAMPO3 = TAB2.CAMPO3 then
acho q é isso , embora naum tenha entendido muito bem o problema.
t+
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)