Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating record based on earliest in, first to be updated 1

Status
Not open for further replies.

codetyko

Programmer
May 26, 2001
73
MY
I have a table of a fixed number of records (10) used to store users' ten most preferred text string which constitutes the first paragraph of a legal document.

The table also stores the time and the date the record was created. What I want to do is when the ten records has been used up, the next string to be saved should occupy the space of the earliest record created with regards to the time and date stored. The next new record should also follow the same rule.

How do I go about it as the ten records may have the same date and how can we issue the instruction to combine the date and time factor?
 
HI
YOu cannot call that as the 10 most preferred. i think, the last 10 records searches.

What you can do is to hav a lop and decide.. since only 10 records are invlolved..

SELECT myTable && holding the 10 records.
GO TOP
nRec = 1
nDateTime = myDateTimeField && which ever way you store
SCAN
IF myDateTimeField < nDateTime && This is older
nRec = RECNO()
nDateTime = myDateTimeField
ENDIF
ENDSCAN
GO nRec
** Now replace the text field...

If you have an index on this dateTime field.. the whle thing is much more simpler.
IF you open the table with this index.. and GO TOP

Hope you get the idea.

Hope this idea helps you :)

ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
codetyko,

First, if you will consider the possibility that more than one record may be updated on the same date, you will have to consider also the time. You will also have to define the precision because, to be exquisite, this time may also coincide.

So, I would create a variable to store this, composed by the date and time. For instance:

m.datetime = VAL(SYS(11,DATE()))* 1000000 + SECONDS()
(Explanation:
SYS(11,DATE() returns the alfanumeric julian day
VAL() transforms it into numeric
* 1000000 adds six zeros
+ SECONDS() adds the seconds from midnight; the maximun is 84000, so that is the need of adding six zeros)

Up to this point, I agree Ramani in creating an index tag on &quot;mytable.datetime&quot; and going to the top of the table to make the replacement.

But still, you have the possibility of:

CALCULATE MIN(mytable.datetime) TO m.mindatetime
LOCATE FOR mytable.datetime = m.mindatetime
REPLACE mytable.datetime WITH m.datetime

Hope this helps!

David.
 
sometimes you cant trust the clock, so use the record number
go bottom
do while !bof()
if go
use this record
exit && never liked to exit loops this way
endif
skip -1
enddo

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top