Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2012
    Posts
    24

    Writing out a variable

    Hi

    I have declared a variable (FoxPro 9.0) as MyVariable ="A name" and want to use MyVariable as a column name for my table. Something like this,

    [...]
    MyVariable ="A name"
    Select LotofValues as MyVariable;
    [...]

    Doing this the column is named MyVariable and not A name as I want. Ideas?

  2. #2
    Join Date
    Nov 2002
    Posts
    108
    First, the results you got should have not been any surprise since you used the standard SQL Query syntax (nothing specific to Visual Foxpro here) as MyVariable which 'tells' the query to make the new field named "MyVariable"

    Secondly no field name may have a space in it so you will NEVER get a field named:
    "A <space> name"
    The best you could do would be to get a field named:
    "A_name" where the underscore replaces your space.

    You can use the CREATE TABLE command to build a new table - defining the field names and types.

    Visual Foxpro data tables can be of 2 types.
    * FREE tables - data tables which are not 'contained' in a VFP Database
    * Database tables - data tables which are 'contained' within a VFP Database

    Quite often many (if not most) of the data tables created and used are FREE tables.

    With FREE tables, field names have more constraints than do the field names of Database tables.

    You should probably use your VFP Help system to learn more detail

    In your Command Window type: HELP system capacities and/or spend some time looking at the free on-line (or downloadable) VFP tutorial videos at:
    Free Visual FoxPro Videos
    which I have recommended to you multiple times.

    Good Luck

  3. #3
    Join Date
    Nov 2002
    Posts
    108
    From a purely SQL Query syntax perspective you could use VFP Macro substitution (using the ampersand character '&') to have your SQL Query field name

    Your code syntax was 'telling' the SQL Query to use the literal "MyVariable" as the new field name.
    Using the VFP Macro substitution would 'tell' the SQL Query to use the Contents of the variable MyVariable as the new Field Name

    So instead of:
    Code:
    MyVariable ="FldName"
    Select LotofValues as MyVariable;
    You could try:
    Code:
    MyVariable = "FldName"
    SELECT LotofValues as &MyVariable;
        FROM MyTable;
        INTO CURSOR Results
    Good Luck

  4. #4
    Join Date
    Nov 2012
    Posts
    24
    Thank you!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •