MySQL Forums
Forum List  »  Delphi

Routine needs Streamlining
Posted by: Jim Sawyer
Date: December 05, 2018 01:09PM

I am using the following routine in Delphi/FireDAC. The RECORDS table has about 3 million records and the routine takes way too much time to be practical. I'm sure it can be streamlined using JOIN, but I can't figure out how to do it. I would like very much if someone can give me some pointers that I can use.

The routine is:

// patient
pQuery := TFDQuery.Create( AConnection );
with pQuery do
begin
Connection := AConnection;
SQL.Add( 'Select Patno, TargSel from Patient where TargSel = true' );
Open;
while not EOF do
begin
// targservice
tsQuery := TFDQuery.Create( AConnection );
with tsQuery do
begin
Connection := AConnection;
SQL.Add( 'Select * from TargService where Targno = :T and AllIn = true' );
ParamByName('T').AsInteger := HotTargno;
Open;
while not EOF do
begin
// records
lAllIn := true;
rQuery := TFDQuery.Create( AConnection );
with rQuery do
begin
Connection := AConnection;
SQL.Add( 'Select Servno from Records where Servno = :S and SSDO = true and RecDate between :St and :E' );
ParamByName('S').AsInteger := tsQuery.FieldValues['Servno'];
ParamByName('St').AsDate := dStart;
ParamByName('E').AsDate := dEnd;
IndexFieldNames := 'Servno';
IndexesActive := true;
Open;
if EOF then
lAllIn := false;
end;
Next;
if not lAllIn then
Break;
end;
if not lAllIn then
AConnection.ExecSQL( 'Update Patient set TargSel = false where Patno = :P',
[pQuery.FieldValues['Patno']] );
end;
Next;
end;
Free;
end;

Thank you.
Jim Sawyer

Options: ReplyQuote


Subject
Written By
Posted
Routine needs Streamlining
December 05, 2018 01:09PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.