Yes, most all fields that are used for sorting/limiting are indexed. I don't know if this is true or not with VFP, but some of the articles that I have read for upper end RDBMS suggest not to index on bit fields (logical). It can only be 1 or 0 (.t. or .f.) and would take as much time as to seequentially go thru each record as it would an index.
As you requested some code, here is the program behind a job bill of materials report (this is one that I created, so there won't be any legal issues). As you can see it is complex. (The standard AccountMate reports are quite a bit more complex, but I don't want to get into legal issues on showing you.) This is called from a report selection form where the user selects what to sort by and the selection criteria. This creates a cursor and calls the actual .frx.
* adding in the history tables
local lcSortA, lcSortB, lcFields1, lcFields2
do case
case lnSortNo = 1
lcSortA = "Jsest.citemno"
lcSortB = "Jsesth.citemno"
* also sort by Seq No
lcOrder = "1, 10"
endcase
if !empty(lcFilter1)
lcFilter1 = " where " + lcFilter1
endif
if !empty(lcFilter1h)
lcFilter1h = " where " + lcFilter1h
endif
lcFields1 = "Jsest.citemno, "+;
"Jsest.cDescript, "+;
"Jsest.nQty, "+;
"Jsest.cRFQNo, "+;
"Jsest.dDueDate, "+;
"Jsest.dDate, "+;
"Jsest.cCustNo, "+;
"Jsest.lFaxed, "+;
"Jsbom.nSeqNo, "+ ;
"Jsbom.cItemNo as cItemNoDet, "+;
"Jsbom.cRevision, "+;
"Jsbom.nLevel, "+ ;
"Jsbom.nQty as nQtyDet, "+;
"Jsbom.nUnitCost as nUnitCostDet, "+;
"Jsbom.cDescript as cDescriptDet, "+;
"Jsbom.cType, "+;
"Jsbom.cSpec, "+;
"Jsbom.nExtCost, "+;
"Jsbom.nExtQty, "+;
"Jsbom.nQtyYield, "+;
"Jsbom.cMatSize, "+;
"Jsbom.cOrdSize, "+;
"Jsbom.cVendorNo, "+;
"Jsbom.dOrder as dOrderDet, "+;
"Jsbom.nDelivery as nDeliveryDet, "+;
"Jsbom.nFreight as nFreightDet," +;
"Jsbom.nrmweight, "+;
"Jsbom.nordLength "
*lcFields2 = HistoryExpr(lcFields1)
lcFields2 = "Jsesth.citemno, "+;
"Jsesth.cDescript, "+;
"Jsesth.nQty, "+;
"Jsesth.cRFQNo, "+;
"Jsesth.dDueDate, "+;
"Jsesth.dDate, "+;
"Jsesth.cCustNo, "+;
"Jsesth.lFaxed, "+;
"Jsbomh.nSeqNo, "+ ;
"Jsbomh.cItemNo as cItemNoDet, "+;
"Jsbomh.cRevision, "+;
"Jsbomh.nLevel, "+ ;
"Jsbomh.nQty as nQtyDet, "+;
"Jsbomh.nUnitCost as nUnitCostDet, "+;
"Jsbomh.cDescript as cDescriptDet, "+;
"Jsbomh.cType, "+;
"Jsbomh.cSpec, "+;
"Jsbomh.nExtCost, "+;
"Jsbomh.nExtQty, "+;
"Jsbomh.nQtyYield, "+;
"Jsbomh.cMatSize, "+;
"Jsbomh.cOrdSize, "+;
"Jsbomh.cVendorNo, "+;
"Jsbomh.dOrder as dOrderDet, "+;
"Jsbomh.nDelivery as nDeliveryDet, "+;
"Jsbomh.nFreight as nFreightDet, "+;
"Jsbomh.nrmweight, "+;
"Jsbomh.nordLength "
do BeforeQuery
select &lcSortB as xSortBy, ;
&lcFields2 ;
from Jsesth, Jsbomh where Jsesth.cItemNo = Jsbomh.cMastItem;
&lcFilter1h ;
union all ;
select &lcSortA as xSortBy, ;
&lcFields1 ;
from Jsest, Jsbom where Jsest.cItemNo = Jsbom.cMastItem;
&lcFilter1 ;
into cursor CurReport ;
order by &lcOrder
if plAborted
return ""
endif
return AfterQuery("Jsbom")
Derek Agar
Acctware Business Systems
derekagar@acctware.comICQ: 42332100
***********************
When in trouble call 911
He that dwelleth in the secret place
of the most High shall abide under
the shadow of the Almighty.
Psalm 91:1
***********************