I insert the code fragment where the query is made on a dbf that contains information about who, when, how long and for what a user has entered to do wich task on which customer. As you can imagine, this dbf can contain hundreds of thousands of records...
// I establish the condition (initial and final values for each field)
cUsuCon := 'USUARIO>="'+cUsuIni+'".and.USUARIO<="'+cUsuFin+'"'
cPueCon := 'PUESTO>="'+cPueIni+'".and.PUESTO<="'+cPueFin+'"'
cDisCon := 'DISTINGO>="'+cDisIni+'".and.DISTINGO<="'+cDisFin+'"'
cCliCon := 'CLIENTE>="'+cCliIni+'".and.CLIENTE<="'+cCliFin+'"'
cNomCon := 'NOMBRE>="'+cNomIni+'".and.NOMBRE<="'+cNomFin+'"'
cYeaCon := 'YEAR>="'+cYeaIni+'".and.YEAR<="'+cYeaFin+'"'
cTarCon := 'TAREA>="'+cTarIni+'".and.TAREA<="'+cTarFin+'"'
cDInCon := 'DtoS(DATEIN)>="'+DtoS(cDInIni)+'".and.DtoS(DATEIN)<="'+DtoS(cDInFin)+'"'
cTInCon := 'TIMEIN>="'+cTInIni+'".and.TIMEIN<="'+CTInFin+'"'
cDOuCon := 'DtoS(DATEOUT)>="'+DtoS(cDOuIni)+'".and.DtoS(DATEOUT)<="'+DtoS(cDOuFin)+'"'
cTOuCon := 'TIMEOUT>="'+cTOuIni+'".and.TIMEOUT<="'+cTOuFin+'"'
cCondicion := cUsuCon + '.and.' + cPueCon + '.and.' + cDisCon + '.and.' + ;
cCliCon + '.and.' + cNomCon + '.and.' + cYeaCon + '.and.' + ;
cTarCon + '.and.' + cDInCon + '.and.' + cTInCon + '.and.' + ;
cDOuCon + '.and.' + cTOuCon
// I Index TEMPORARY.dbf (it will contain the records that meet the condition)
USE &(cFileDbf) ALIAS TEMPORAL EXCLUSIVE NEW
INDEX ON (Usuario) TAG 1 TO &(cFileCdx)
INDEX ON (Distingo) TAG 2 TO &(cFileCdx)
INDEX ON (Cliente) TAG 3 TO &(cFileCdx)
INDEX ON (Nombre) TAG 4 TO &(cFileCdx)
INDEX ON (Year) TAG 5 TO &(cFileCdx)
INDEX ON (Tarea) TAG 6 TO &(cFileCdx)
INDEX ON (DateIn) TAG 7 TO &(cFileCdx)
CLOSE TEMPORAL
USE &(cFileDbf) INDEX &(cFileCdx) ALIAS TEMPORAL EXCLUSIVE NEW
// I open the query database
Select SHERLOCK
dbGoTop()
// Testing index in memory
nSecIni := Seconds()
cIndexKey := IndexKey()
INDEX ON &(cIndexKey) TAG _TEMP_ TO tHarbourt FOR &(cCondicion) ADDITIVE MEMORY &&(aqui da error de longitud; Len(cCondicion)=561 !!!)
OrdSetFocus( "_TEMP_" )
dbGoTop()
// I fill TEMPORARY with records from SHERLOCK
do while Eof()==.F.
if &cCondicion
Select TEMPORAL
dbAppend()
for i:=1 to fCount()
FieldPut(i, SHERLOCK->(FieldGet(i)))
next
endif
Select SHERLOCK
dbSkip()
enddo
// Testing index in memory
OrdDestroy("_TEMP_")
OrdSetFocus( "1" )
nSecFin := Seconds()
// Processing time
Alert('Consulta procesada en Segundos... '+AllTrim(Str(nSecFin-nSecIni)))