la cuestion es la siguiente, yo con este codigo realizo la union de varios campos, de una tabla de personal, y otra de horas, validaqndo todo, y haciendo una validacion solo para que me tome 1 entrada y ultima salida por dia, todo el mes para imprimirlo en un reporte, y el union lo uso para pasar el registro que no este en la tabla hora ejmeplo, un sabado que no tenga asistencia, lo pone como registro vacio, para vizualizarlo en el reporte, y se vean los 31 dias del mes. ah tambien tengo fotos dentro de la bases de datos
Código Delphi
[-]var
op,b,boton:integer;
nombref:PChar;
begin
if RadioButton1.Checked=true then op:=1;
case op of
1:begin
b:=0;
with tabla.IBQuerypersonal do begin
SQL.Clear;
Close; sql.Add('select * from personal where ( Ubicacion='+QuotedStr('CIRCUITO DE TRABAJO')+' or
Ubicacion='+QuotedStr('DEPARTAMENTO1')+' ) and status='+QuotedStr('Activo')+'
and ( modcargo='+QuotedStr('Fijo')+' or modcargo='+QuotedStr('Contratado')+' or
modcargo='+QuotedStr('TITULAR')+' or modcargo='+QuotedStr('CONTRATADO')+')
order by nombre asc');
Prepare;
open;
while not eof do begin
DataSource1.DataSet:=tabla.IBQHorasrep2;
dINI := DateTimePicker1.Date;
Dfin := DateTimePicker2.Date;
nDATO := (dINI + strtofloat('20'));
nDIAS := Trunc(dFIN - dINI);
with Tabla.IBQHorasrep2 do begin
sql.Clear;
Close;
FOR I := 0 TO nDIAS DO
BEGIN
nDATO := (dINI + STRTOFLOAT(INTTOSTR(I)));
dFECHA := FLOATTODATETIME(nDATO);
cFECHA := FormatDateTime('mm/dd/yyyy', dFECHA);
SQL.Add('select min(h.he),max(h.hs),CAST('+QuotedStr(cFECHA)+' AS DATE)
F1,p.nombre,p.apellido,p.cedula,h.fecha');
SQL.Add('from personal p left join horas h on h.cedula=p.cedula and h.fecha='+QuotedStr(cFECHA)+'');
SQL.Add('where p.cedula = arcedula and p.status ='+QuotedStr('Activo')+'');
SQL.Add('group by p.cedula, p.nombre, p.apellido,h.fecha,3'); IF I < nDIAS THEN
BEGIN
SQL.Add(' UNION ');
END
ELSE
BEGIN
SQL.Add(' order by 3,1 ');
END
END;
Prepare;
ParamByName('parcedula').AsString:=tabla.IBQuerypersonalCEDULA.AsString;
Open;
end;
if tabla.IBQuerypersonalFOTO.IsNull then begin
Image1.Picture:=nil;
end else begin
if tabla.IBQuerypersonalFORMATOFOTO.AsString ='BMP' then
image1.Picture.Graphic:=TBitmap.Create
else if tabla.IBQuerypersonalFORMATOFOTO.AsString ='JPG' then
Image1.Picture.Graphic:=TJpegImage.Create
else
exit;
m:=tabla.IBQuerypersonal.CreateBlobStream(tabla.IBQuerypersonalFOTO,bmread);
Image1.Picture.Graphic.LoadFromStream(m);
m.Free;
end;
b:=b+1;
label4.Caption:= inttostr(b);
Boton := Application.MessageBox ('¿Está Seguro que Desea Imprimir este registro?',
'Print',MB_YESNO+MB_ICONQUESTION);
If Boton = ID_YES Then begin
form20.QRLabel19.Caption:=DBEdit4.Text;
form20.QRLabel2.Caption:=DBEdit1.Text;form20.QRLabel3.Caption:=DBEdit3.Text; form20.QRLabel5.Caption:=DBEdit2.Text;
form20.QRLabel4.Caption:=tabla.IBQuerypersonalCEDULA.AsString; Form20.QuickRep1.Prepare;
form20.QuickRep1.Print;
end
Else begin
end;
tabla.IBQuerypersonal.next;
end;
tabla.IBQuerypersonal.first;
end;
end;
end;
end;
este codigo da perfecto, pero cuando lo ejecuto en un while do para que se haga 120 veces obvio que consume mucha memoria