KAM.covad wrote:
> I have a table with a date field: dDate and thousands of records.
> 
> The dates are scattered over time including the future. I need to find the 
> record with the max date that is =< required date.
> 
> How would you do this with sql select and also with Locate?

* sql select
* I use 2 statements because the first one will execute really fast without 
needing
* to pull in irrelevant records. Make sure you have an index on dDate.
* Note the final result could contain multiple records; you didn't specify how 
to
* determine the *one* record you need other than the specified date.

select max(dDate)
   from <table>
  where dDate <= ?
   into array atemp

dDate = atemp[1]

select *
   from <table>
  where dDate == m.dDate


* locate
select <alias>
* index on dDate descending tag dDate_desc
set order to tag dDate_desc
set near on
locate for dDate = ?

* you are now on the first record with the date <= to the specified date.

Note my fox is rusty. I see I forgot the semicolons, for instance. So consider 
this 
pseudocode.

Paul



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to