cdaviduik


I would like to create a SQL SELECT statement in VFP9 but instead of specifying the table explicitly I would like it to be read from a variable. For example:

TABLE_NAME = "table_to_select"

SELECT * FROM TABLE_NAME;
INTO CURSOR tbl_cur

and when I execute the above I would actually like this to happen:

SELECT * FROM table_to_select
INTO CURSOR tbl_cur

Any ideas on how to do this I have not been able to find a solution with VFP9 help or within the forums.
Thank you.



Re: SQL Select using variables

Markish


Hi,

It can be done through use of macros...

Code Snippet

Table_name='table_to_select'

select * from &table_name into cursor tbl_cur

Best regards,

Markish







Re: SQL Select using variables

hangover

or using a name expression, e.g.

Code Snippet

SELECT * FROM (TABLE_NAME) ;

INTO CURSOR tbl_cur

Dom







Re: SQL Select using variables

Naomi Nosonovsky

Not OR Smile Using the name expression in this context is the right answer.

You don't want to use macros when unnecessary.





Re: SQL Select using variables

Tamar E. Granor

And name expressions work in some cases where macros don't, specifically when there are spaces in the path.

Tamar




Re: SQL Select using variables

cdaviduik

Thank you very much for your help!