Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Examples / discussion of strings in Sql syntax
Message
De
26/10/1999 18:17:00
 
 
À
26/10/1999 17:19:42
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00281879
Message ID:
00281907
Vues:
17
>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
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform