Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to subquery in VFP 8
Message
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
How to subquery in VFP 8
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01046845
Message ID:
01046845
Vues:
144
I combine two fields from the same table into one field (with the help from Fabio and Sergey in another thread).

Now I need to select only some records from the resulting cursor. And to do that, as far as I know, I need to run a subquery within a SQL Select. But there I get an error that the table does not exist.

Here is an example:

The cursor MYCURS:

ROOM RES_TIME PK_VALUE
A100 11:00 3434
A100 15:00 34566
B100 15:00 2
B100 17:00 899
and so one

I need to select only those records that match the latest Reservation time. That is, in the example above, the resulting cursor would have:

A100 15:00
B100 17:00

So what I do is the following
select * from MYCURS1 where PK_VALUE = MyFunc(ROOM) into cursor MYCURS2

Function MyFunc
lparameter	tcRoomNum
local array	laKeys[1]	
select top 1 RESER_PK, END_TIME from MYCURS1 		;
where ROOM == tcRoomNum order by END_TIME descending into array laKeys
IF _tally > 0
	RETURN laKeys[1]
ELSE
	RETURN 0
endif		
RETURN
And I get error in the Select TOP 1 that cursor/table MYCURS1 does not exist.

How could I fix this?

Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform