Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to subquery in VFP 8
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01046845
Message ID:
01046849
Vues:
24
Try
SELECT room, MAX(res_date) AS max_date ;
	FROM mycurs1 ;
	GROUP BY 1 ;
	INTO CURSOR crsMaxRes
*
SELECT * FROM mycurs1 ;
	WHERE room + res_date IN ( ;
		SELECT room + max_date ;
			FROM crsMaxRes )
* or 
SELECT mc1.* FROM mycurs1 mc1 ;
	JOIN crsMaxRes mr ON mr.room = mc1.room ;
	AND mr.max_date = mc1.res_date
>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.
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform