Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to select fields without hard-coding?
Message
From
23/03/2008 06:52:44
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01304667
Message ID:
01304668
Views:
22
>Good morning,
>
>I need to create a routine of selecting (using SQL Select) only certain fields from a table/cursor. The fields that are to be selected should not be hard coded into the SQL Select. For example, if I could create an array where the fields would be stored, as e.g.:
>
>
>local array aFlds[3]
>aFlds[1]="myfld1"
>aFlds[2]="myfld2"
>aFlds[3]="myfld3"
>
>
>If I could then use this array in the SQL select to select only these fields. Is something like this possible?
>
>Any other suggestions?

Make the sql statement, then macro-exeucte it or pass it to an sqlexec()
local i, s, aFlds[3]
aFlds[1]="myfld1"
aFlds[2]="myfld2"
aFlds[3]="myfld3"
	
s = ''
for i = 1 to alen(aFlds, 1)
	s = m.s + ',' + aFlds[m.i]
endfor
	
s = 'select ' + substr(m.s, 2) + ' from Table '
	
&s
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform