Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Finding data in table
Message
 
 
To
17/03/2003 14:53:16
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00766682
Message ID:
00766698
Views:
31
>I would like to find (and print) the last record in a table that has specific data.
>
>Example: a table consisting of 300 records, record numbers 3, 41 & 250 has the field (field.computer) populated with the name "hellcat". I would like to find/print record number 250. (The tricky part of course is, I do not know that recno()=250 has the data I need.)
>
>Any help on the proper syntax is greatly appreciated.
>
>Thanks,
>Billy
Select Top 1 * ;
	From SourceTable ;
	Into Cursor curToPrint ;
	Where SourceTable.Computer = "hellcat" ;
	Order By Computer Desc
Since (in your example above) all three resulting rows have the value "hellcat" it may be that the DESC clause will not reverse the record order. If this is the case then you might be able to use:
Select Top 1 *, RecNo() as Rec_No ;
	From SourceTable ;
	Into Cursor curToPrint ;
	Where SourceTable.Computer = "hellcat" ;
	Order By Rec_No Desc
PS. Some people will frown upon the use of RecNo() in SQL statements because the current work area / alias automatically changes during the SELECT. This is because VFP does something similar to a USE AGAIN (in a different data session). However since only one table is involved there should not be a problem.
censored.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform