Fórum select Lento ?????? #189789

20/10/2003

0

Prezado Colega,


Estou com problemas com select lento, pois tenho que listar em um extrato de clientes, Contas em aberto e parcelas pagas.

Tenho duas tabelas, Receber e ParcRec, na tabelas receber, guardo debito de clientese na parcrec as parcelas.

Exemplo: Valor => R$ 100 Saldo => 40,00 (RECEBER)
PARCELA 01 => R$ 30,00 (PARCREC)
PARCELA 02 => R$ 30,00 (PARCREC)

Rotina:


DM_dados.Qr_receber.Close;
DM_dados.Qr_receber.SQL.Clear;
DM_dados.Qr_receber.SQL.Add(´SELECT * from receber WHERE ´ +
´LOJA = :P00 and CLIENTE = :P01 ´ +
´ORDER BY CONTROLE,DOCUMENTO,PARCELA ´);

DM_dados.Qr_receber.Params[00].Text := Edit_loja.text;
DM_dados.Qr_receber.Params[01].Text := Edit_Cliente.text;
DM_dados.Qr_receber.Open;

DM_Dados.Qr_receber.first;
while not DM_dados.Qr_receber.eof do
begin
with rdprint1 do // Componente de Relatorio
begin
if scont <> Dm_dados.Qr_receber.fieldbyname(´DOCUMENTO´).AsString then
begin
imp (linha,01,traco);
inc(linha);

end;

impF(linha,08,DM_dados.Qr_receber.Fieldbyname(´EMISSAO´).AsString, []);
impF(linha,20,DM_dados.Qr_receber.Fieldbyname(´PARCELA´).AsString, []);
impF(linha,31,DM_dados.Qr_receber.Fieldbyname(´VENCIMENTO´).AsString, []);
impF(linha,42,DM_dados.Qr_receber.Fieldbyname(´DATA_RECEBIMENTO´).AsString, []);

////////////////////////

vjuros:= 0;
juros := 0;
dia:= 0;
if DM_dados.Qr_receber.fieldbyname(´SALDO´).AsFloat > 0 then
begin
if (DM_dados.Qr_receber.fieldbyname(´DATA_RECEBIMENTO´).AsString = ´´ ) then
dia := date - DM_dados.Qr_receber.FieldByName(´VENCIMENTO´).AsDateTime
else dia := DM_dados.Qr_receber.fieldbyname(´DATA_RECEBIMENTO´).AsDateTime - DM_dados.Qr_receber.fieldbyname(´VENCIMENTO´).AsDateTime;
if DM_dados.Qr_receber.FieldByName(´SALDO´).AsFloat < 0.01 then
dia := DM_dados.Qr_receber.FieldByName(´DATA_RECEBIMENTO´).AsDateTime - DM_dados.Qr_receber.FieldByName(´VENCIMENTO´).AsDateTime;
juros := DM_dados.empresa.fieldbyname(´JUROS´).AsFloat / 31 * dia;
vjuros := (DM_dados.Qr_receber.fieldbyname(´SALDO´).AsFloat * juros/100);
if juros <= 0 then vjuros := 0;
end else
begin
dia:= 0;
if DM_dados.Qr_receber.FieldByName(´DATA_RECEBIMENTO´).AsString <> ´´ then
dia := DM_dados.Qr_receber.FieldByName(´DATA_RECEBIMENTO´).AsDateTime - DM_dados.Qr_receber.FieldByName(´VENCIMENTO´).AsDateTime;
end;
dias := floattostr(dia);
if dia <= 0 then dias := ´´;
/////////////////////
impf(linha,53,dias,[]);

IF DM_dados.Qr_receber.Fieldbyname(´SALDO´).AsFloat = 0 then
impval(linha,59,´#,0.00´, DM_dados.Qr_receber.Fieldbyname(´VALOR_RECEBIDO´).value,[]);
IF DM_dados.Qr_receber.Fieldbyname(´SALDO´).AsFloat > 0 then
impF(linha,59,´ ABERTO´,[]);
impval(linha,69,´,0.00´, DM_dados.Qr_receber.Fieldbyname(´VALOR´).value,[]);

impval(linha,79,´0.00´, vjuros,[]);
impval(linha,87,´,0.00´, DM_dados.Qr_receber.Fieldbyname(´SALDO´).value+vjuros,[]);
inc(linha);

===================//////////////////////

DM_dados.QR_parcrec.Close;
DM_dados.QR_parcrec.SQL.Clear;
DM_dados.QR_parcrec.SQL.Add(´SELECT * from parcrec WHERE ´ +
´LOJA = :P00 and CLIENTE = :P01 ´ +
´and PARCELA = :P02 ORDER BY CONTROLE,DOCUMENTO,PARCELA,RECIBO ´);

DM_dados.QR_parcrec.Params[00].Text := Edit_loja.text;
DM_dados.QR_parcrec.Params[01].Text := Edit_Cliente.text;
DM_dados.QR_parcrec.Params[02].ASString := DM_dados.QRY0.Fieldbyname(´PARCELA´).ASstring;
DM_dados.QR_parcrec.Open;


if not DM_dados.QR_parcrec.IsEmpty then
begin


DM_dados.QR_parcrec.open;
while not DM_dados.QR_parcrec.eof do
begin

impF(linha,01,´==> P0´+DM_dados.QR_parcrec.Fieldbyname(´RECIBO´).AsString, []);
impF(linha,11,DM_dados.QR_parcrec.Fieldbyname(´DATA´).AsString, []);
impval(linha,25,´#,0.00´, DM_dados.QR_parcrec.Fieldbyname(´VALOR_RECEBIDO´).value,[]);


inc(linha);
DM_dados.QR_parcrec.next;
end;
end;

=========================== ///////////////////
end;
DM_Dados.Qr_receber.next;
end;


Claudiomar

Claudiomar

Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar