select price from tranmstr where between(tranid,100000,100500) into cursor curPrice set order to price desc ?_tally goto 251 ?price browIt automatically has index on price, though I don't understand why. The result has 501 records, I issue goto 251 and ?price. It returns 85062 (correct). Also I noticed, that when I try to Browse this cursor it takes too much time. TranMstr table is very large, BTW.
*************************************************************************** * Description.......: GetMedian - returns median value from a specified table * Calling Samples...: GetMedian('curPrice','LstSlPrice') * Parameter List....: pcTableName, pcField * Created by........: Nadya Nosonovsky 10/24/2000 01:58:18 PM * Modified by.......: Nadya Nosonovsky 10/25/2000 11:43:05 AM ***************************************************************************** * Returns median value or .f. for unsuccessful cases lparameters pcTableName, pcField local lcTableName, lnOldSelect, lnMedianValue, llCloseDBF, lnMiddleRecord, lcOrder * pcTableName - name of the table or already opened cursor, which should be processed * pcFiled - name of the field, which used in calculation, price, for example * Both parameters are optional, if they are not specified, current working alias is used and price field lnOldSelect=select() && Save current area llCloseDBF=.f. if empty(pcField) or vartype(pcField)'C' pcField=upper('price') else pcField=upper(pcField) endif if empty(pcTableName) or vartype(pcTableName)'C' pcTableName=alias() && Current open alias if empty(pcTableName) && No current table return .f. endif lcTableName=pcTableName && Alias else lcTableName=justfname(pcTableName) && Only Table Name without path if not used(lcTableName) && The table was not used previosly local fh fh=fopen(pcTableName,12) if fh>0 and fclose(fh)>0 && File could be open exclusevely use pcTableName again shared in 0 alias lcTableName llCloseDBF=.t. else =messagebox(pcTableName +' is opened exclusively by another user. Can not proceed...',48) return .f. && Table could not be opened (already used exclusively) endif endif endif select (lcTableName) lnRecords=reccount() && Total number of records if lnRecords0 and fclose(fh)>0 && File could be open exclusevely use dbf(lcTableName) again exclusive in 0 alias WorkTable index on &pcField tag (pcField) use in WorkTable else =messagebox(pcTableName +' is opened exclusively by another user. Can not proceed...',48) return .f. && Table could not be opened (already used exclusively) endif else endif select (lcTableName) set order to (pcField) descending && Now it has this tag lnMiddleRecord=ceiling(lnRecords/2) goto lnMiddleRecord lnMedianValue= evaluate(lcTableName+'.'+pcField) && Field content if llCloseDBF use in (lcTableName) else set order to (lcOrder) endif select (lnOldSelect) && Return to old area return lnMedianValueThanks in advance.