>I want to have several cases where a string is placed in an SQL statement. I would appreciate some reference to an article like "Using strings and string variables in VFP 6.0 SQL statements." Does anyone have examples?
>
A string can be used pretty much anyplace that a character literal can be used in a native SQL Select statement; IOW, if it's legal to say:
SELECT * FROM MyTable WHERE MyField = "ABCDE"
It'll be legal to say:
cMyStringVar = "ABCDE"
SELECT * FROM MyTable WHERE MyField = cMyStringVar
You can use a string in a name expression to replace a file or field name by encapsulating the string in parentheses. Using the simple example above, the following examples are legal:
cMyStringVar = "MyTable"
SELECT * FROM (cMyStringVar) WHERE MyField = "ABCDE"
cMyStringVar = "MyField"
SELECT * FROM MyTable WHERE (cMyStringVar) = "ABCDE"
Macro expansion is a technique which makes VFP evaluate the content of a string and treat the evaluated expression as a part of the command line. Macro expansion is done by prefixing the string with a single & character. The following are examples of this:
cMyStringVar = 'WHERE MyField = "ABCDE"' && note the use of ' and "
SELECT * FROM MyTable &cMyStringVar
cMyStringVar = "MyField, Fld2 AS OtherName"
SELECT &cMyStringVar FROM MyTable WHERE MyField = "ABCDE"
cMyStringVar = "SELECT * FROM MyTable WHERE MyField = 'ABCDE'" && Note ' and "
&cMyStringVar
cMyStringVar = '"ABCDE","FGHIJ","KLMNO"' && again ' and "
SELECT * FROM MyTable WHERE MyField IN (&cMyStringVar)
You can mix usages of strings within a single statement:
cString1 = "MyTable"
cString2 = "WHERE MyField IN ('ABCDE','FGHIJ','KLMNO')" && again ' and "
SELECT * FROM (cString1) &cString2
The three basic usages for strings shown here are:
(1) Literal equivalence, substituting a string variable for a literal
(2) Name equivalence, substituting the content of string variable for a name
(3) Macro substitution, replacing all or part of a command with the content of a string
Hope this helps; if you have specific questions just ask...
>Thanks for assistance.
>Sylvia