If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Other PC Databases > Writing out a variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
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?
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Nov 2012
Posts: 24
Thank you!!!!!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On