Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using a variable in a select statement
Message
De
02/09/1997 17:31:50
 
 
À
28/08/1997 18:34:32
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00047445
Message ID:
00048121
Vues:
25
>>Hi all...
>>
>>Is it possible to use a variable in place of a field name in a select statement?
>>
>>My form will have a combo box from which the user can select a number of different options each of which refers to a different field in the same table. The user then can enter text in a text box which represent what they want to find in that field.
>>
>>So, when they click a button (like "Find"), the following is executed:
>>
>>VarFieldName = thisform.cmbField.value
>>VarFieldText = thisform.txtField.value
>>select * from table_name where table_name.VarFieldName = VarFieldText
>>
>>I get the following error:
>>SQL: Column 'VARFIELDNAME' is not found.
>>
>>It would appear that VFP is not substituting my variable name for the field with the "real" field name.
>>(Gosh, I amaze myself sometimes! <g>)
>>
>>Any suggestions? ( I mean, other than creating a series of if/endif for every possible value in the combo box.)
>>
>>tia,
>>
>>marc mandel
>
>This is the normal behavior. Use a macrosubstitution:
>
>select * from table_name where table_name.&VarFieldName = VarFieldText

You may also use something like this:

cSQLCommand = 'SELECT * FROM table_name WHERE ' + VarFieldName + '="' + thisform.cmbField.value + '"'

then use &cSQLCommand to run the query.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform