Sergey,
A variation on the theme (at least I think I see a theme developing in this thread):
SELECT DISTINCT KeyField ;
FROM AnotherTable ;
INTO CURSOR KeyCursor
INDEX ON KeyField TAG KeyField
SELECT MyTable
SCAN FOR INDEXSEEK(MyTable.KeyField, .F., "KeyCursor", "KeyField")
... do stuff
ENDSCAN
USE IN KeyCursor
Advantages:
Not relying on a SET RELATION.
Faster... when your doing an INDEXSEEK("", .F.) the record pointer in KeyCursor doesn't move. You're just traversing the CDX.
One thing you absolutely do not want to do is add a UDF to a SQL query. VFP will run the UDF with every row of the source cursor, which KILLS performance.
Regards,
Thom C.
>>In this case just reverse reletationship
SELECT KeyField from AnotherTable Into Cursor KeyCursor
INDEX ON KeyField TAG KeyField
SELECT Mytable
SET RELATION TO KeyField INTO KeyCursor
SCAN FOR FOUND("KeyCursor")
...
ENDSCAN