Master/Detail com 3 tabelas
Como montar um master detail com 3 tabelas usando o delphi7, firebird e QRPT?
Tenho que emitir um relatorio onde tenho as seguintes tabelas:
TB_CLIENTES
TB_ENDERECOS
TB_TELEFONES
As tabelas TB_ENDERECOS e TB_TELEFONES possuem um campo chamado COD_LIGACAO_CLIENTE que é onde eu faço a amarração dos dados. Fazer relatório Master/Detail usando duas tabelas no QRPT eu consigo fazer tranquiamente .... mas com 3 tabelas ja tentei de tudo e não consegui mesmo.
Se alguem puder me ajudar ...
valeww
Tenho que emitir um relatorio onde tenho as seguintes tabelas:
TB_CLIENTES
TB_ENDERECOS
TB_TELEFONES
As tabelas TB_ENDERECOS e TB_TELEFONES possuem um campo chamado COD_LIGACAO_CLIENTE que é onde eu faço a amarração dos dados. Fazer relatório Master/Detail usando duas tabelas no QRPT eu consigo fazer tranquiamente .... mas com 3 tabelas ja tentei de tudo e não consegui mesmo.
Se alguem puder me ajudar ...
valeww
Mmoreira
Curtidas 0
Respostas
Rm
02/11/2004
Talvez ajude...Tempos atras tive o mesmo problema.A solução que encontrei foi fazer uma tabela auxiliar em que os dados de duas tabelas detail fossem lançados.O quickrep é com os campos da table auxiliar
É necessário descobrir qual tem mais registros para insert e qual tem menos registros para edit na tabela auxiliar .O codigo ficou como segue.
var
recs1,recs2:integer;
begin
with datamodule5 do begin
recs1:=Table8.RecordCount;//CONTAR REGISTROS
recs2:=table9.RecordCount;//CONTAR REGISTROS
if recs1>=recs2 then begin// SE TABLE 8 COM + REGISTROS
table8.First;
table10.first;
while not table10.eof do begin//LIMPO TABELA AUXILIAR
table10.delete;
end;
while not table8.eof do begin
table10.insert;//TABELA AUXILIAR INSERIR
table10RH.VALUE:=table8rh.value;
table10Qtd.value:=table8qtd.value;
table8.next;
end;
TABLE10.FIRST;//TABELA AUXILIAR EDIT CAMPOS TABLE COM <RECS
table9.first;
while not table9.eof do begin
table10.Edit;
table10MQ.VALUE:=table9mq.value;
table10QtdMQ.value:=table9qtdmq.value;
TABLE10.next;
table9.next;
end;
end; //até aqui se recs1>=recs2
if recs1<recs2 then begin//SE É AO CONTRÁRIO +RECS NA TABLE9
table9.First;
table10.first;
while not table10.eof do begin
table10.delete;//LIMPA IGUAL
end;
while not table9.eof do begin//INSERE
table10.insert;
table10mq.VALUE:=table9mq.value;
table10Qtdmq.value:=table9qtdmq.value;
table9.next;
end;
TABLE10.FIRST;//EDITA
table8.first;
while not table8.eof do begin
table10.Edit;
table10rh.VALUE:=table8rh.value;
table10Qtd.value:=table8qtd.value;
TABLE10.next;
table8.next;
end;
end;
form8.quickrep1.preview;//DEPOIS DE TUDO
end;
end;
É necessário descobrir qual tem mais registros para insert e qual tem menos registros para edit na tabela auxiliar .O codigo ficou como segue.
var
recs1,recs2:integer;
begin
with datamodule5 do begin
recs1:=Table8.RecordCount;//CONTAR REGISTROS
recs2:=table9.RecordCount;//CONTAR REGISTROS
if recs1>=recs2 then begin// SE TABLE 8 COM + REGISTROS
table8.First;
table10.first;
while not table10.eof do begin//LIMPO TABELA AUXILIAR
table10.delete;
end;
while not table8.eof do begin
table10.insert;//TABELA AUXILIAR INSERIR
table10RH.VALUE:=table8rh.value;
table10Qtd.value:=table8qtd.value;
table8.next;
end;
TABLE10.FIRST;//TABELA AUXILIAR EDIT CAMPOS TABLE COM <RECS
table9.first;
while not table9.eof do begin
table10.Edit;
table10MQ.VALUE:=table9mq.value;
table10QtdMQ.value:=table9qtdmq.value;
TABLE10.next;
table9.next;
end;
end; //até aqui se recs1>=recs2
if recs1<recs2 then begin//SE É AO CONTRÁRIO +RECS NA TABLE9
table9.First;
table10.first;
while not table10.eof do begin
table10.delete;//LIMPA IGUAL
end;
while not table9.eof do begin//INSERE
table10.insert;
table10mq.VALUE:=table9mq.value;
table10Qtdmq.value:=table9qtdmq.value;
table9.next;
end;
TABLE10.FIRST;//EDITA
table8.first;
while not table8.eof do begin
table10.Edit;
table10rh.VALUE:=table8rh.value;
table10Qtd.value:=table8qtd.value;
TABLE10.next;
table8.next;
end;
end;
form8.quickrep1.preview;//DEPOIS DE TUDO
end;
end;
GOSTEI 0
Mmoreira
02/11/2004
sobe
GOSTEI 0