gracias eflosten por la respuesta,
muestro el proceso completo para que se entienda mejor,
un código vale más que mil palabras, sobre todo si son mías
este es el resultado de una form modal dónde se hace la selección de las tiendas :
Código Delphi
[-]
procedure TFDlgSlccionMltple.BtnOkClick(Sender: TObject);
var
Marca : TBookmark;
begin
isqlselmult := ''; with cdsTDAS do
begin
DisableControls;
Marca := GetBookMark;
try
First;
while not cdsTDAS.EOF do begin
if FieldByName('tmp_select').AsBoolean then
begin
if (isqlselmult = EmptyStr) then
begin
isqlselmult := 'centro = ' + cdsTDAS.fieldbyname('com').AsString;
end else begin
isqlselmult := isqlselmult + ' or centro = ' + cdsTDAS.fieldbyname('com').AsString;
end;
end;
Next;
end;
finally
GoToBookmark(Marca);
FreeBookmark(Marca);
EnableControls;
end;
end;
end;
esta es la llamada a mostrar la form modal de selección de las tiendas y la cadena completa del qry con los
where :
Código Delphi
[-]
procedure TFInfrmes_SupSelect.btn5Click(Sender: TObject);
begin
with TFDlgSlccionMltple.Create(self) do begin
try
if ShowModal = mrok then
begin
isqldetsel := 'SELECT centro, max(fecha) as fecha, cdgodiet, sec_to_time(SUM(time_to_sec(hllmndo))) AS rhllmndo, ' +
'SUM(visitas) AS rvisitas, SUM(motnotot) AS rmotnotot, SUM(visitas) + SUM(motnotot) AS rcntctos, ' +
'SUM(motno01) AS rmotnotot01, SUM(motno02) AS rmotnotot02, SUM(motno03) AS rmotnotot03, SUM(motno04) AS rmotnotot04, ' +
'SUM(motno05) AS rmotnotot05, SUM(motno06) AS rmotnotot06, SUM(motno07) AS rmotnotot07, SUM(motno08) AS rmotnotot08, ' +
'SUM(motno09) AS rmotnotot09, SUM(motnoes02) AS rmotnototes01, SUM(motnoes02) AS rmotnototes02, ' +
'SUM(segllam) AS rsegllam, SUM(vllamdec) AS rvllamdec, SUM(llamtot) AS rllamtot, SUM(impventas) AS rimpventas ' +
'FROM tb03P WHERE ((fecha between :fdesde and :fhasta) AND (' + isqlselmult +'))' +
'GROUP BY tb03P.centro ' +
'order by tb03P.centro, tb03P.fecha desc;';
end;
finally
Free;
end;
end;
end;
lanzo el qry de cálculos :
Código Delphi
[-]
with zroqryinfrme_sup do
begin
Close;
sql.Clear;
SQL.Add(isqldetsel); ParamByName('fdesde').AsDate := dteeddtefdesde.Date;
ParamByName('fhasta').AsDate := dteeddtefhasta.Date;
Open;
if zroqryinfrme_sup.RecordCount = 0 then
begin
MessageDlg('No se han encontrado registros en las Fechas seleccionadas.', mtWarning, [mbOK], 0);
zroqryinfrme_sup.Close;
dteeddtefdesde.SetFocus;
end;
end;
haciendo pruebas he seleccionado las 1.200 tiendas y el qry de resultados ha tardado menos de 4 segundos en calcular los datos de los partes (150 registros ahora mismo), teniendo en cuenta que es un mysql remoto vía adsl... como lo véis ??
lo que me da miedo es el día que la tabla de los partes tenga miles de registros y seleccionen todas las tiendas....
se admiten sugerencias