>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.
select * from myCurs1 c1 ;
where end_time = ;
(select max(end_time) from myCurs1 c2 where c1.room == c2.room)
Cetin