Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Fewer steps to get to a certain record in a table?
Message
De
20/07/2001 08:12:44
 
 
À
20/07/2001 08:02:26
Mark Hall
Independent Developer & Voip Specialist
Keston, Kent, Royaume Uni
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00533040
Message ID:
00533055
Vues:
15
>Hi,
>
>If your table is indexed on the date field:
>
><Code>
>lnYear = 1997
>SELECT MyTable
>SET ORDER TO myDate
>SET NEAR ON
>SEEK( DATE(lnYear + 1, 1, 1))
>IF YEAR( myDate) > lnYear AND NOT BOF()
>skip -1
>ENDIF
></Code>
>
>
>should do the trick. The only hole is if there are no records for the year in which you want to find the last entry, but a bit more checking would solve that.

Mark / Steve

Another way to achieve a similar result is to sort the table descending then seek on the year you want
Flip the index back to normal order again and you are on the last year in the list.

EG..
Use in Select('MyCursor')
create cursor MyCursor (MyDate D)

For iYear = 1990 to 2100
	For iMonth = 1 to 10
		Insert into Mycursor Values(ctod(Alltrim(Str(iMonth)) + '/01/' + Alltrim(str(iYear))))
	Next
Next

Index on YEAR(myDate) tag yDat
Set order to tag yDat descending
=Seek('2001')
Set order to Tag yDat Ascending
*!* We are now on the last record for 2001
HTH
Will Jones
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform