You are currently offline, waiting for your internet to reconnect

How to use wildcard characters in the SQL-SELECT statement in Visual FoxPro

This article was previously published under Q98434
SUMMARY
To broaden the selections of a structured query language (SQL-SELECT) statement,two wildcard characters, the percent sign (%) and the underscore (_), canbe used.

The percent sign is analogous to the asterisk (*) wildcard character usedwith MS-DOS. The percent sign allows for the substitution of one or morecharacters in a field.

The underscore is similar to the MS-DOS wildcard question mark character. The underscore allows for the substitution of a single characterin an expression. Three examples showing the use of these characters in SQL-SELECT statements are provided below. The examples use the Customer.dbf file thatis included with Microsoft Visual FoxPro in the Home(2)+data folder.
MORE INFORMATION
The following SELECT-SQL statement returns all the records from the Customer.dbftable that contain a "W" as the first character in the Regionabbreviation field. TheSELECT-SQL statement lists the records from "WY" and "WA" in a Browsewindow.
   SELECT * from customer WHERE Region like "W_"				
The following SELECT-SQL statement lists all the records that have a "P" or a "C" as the last character in the Regionabbreviation field. The output includesrecords from "SP" and "BC."
   SELECT * from customer WHERE Region like "_P" OR region like "_C"				
The following SELECT-SQL statement uses the percent sign and the underscore toreturn all the records that have a Cust_ID that starts with "G" andthat have a Regionabbreviation field that ends with "P."

Note The percent signlets any string of characters follow the "G." Conversely, theunderscore permits the substitution of only a single character.
 SELECT * FROM Customer WHERE cust_ID LIKE "G%"  AND region LIKE "_P"				
To do a string search similar to the one performed by the $ function, use astatement like:
SELECT * from customer WHERE company like "%M%"				
This SELECT-SQL statement finds all companies that have names that contain "M."
REFERENCES
For additional information, see the Visual FoxPro Help files. Search for "SELECT - SQL."
VFoxWin FoxDos FoxWin wild card select kbvfp300 kbvfp500 kbvfp600 search
Properties

Article ID: 98434 - Last Review: 02/12/2007 20:53:38 - Revision: 3.4

Microsoft Visual FoxPro 7.0 Professional Edition, Microsoft Visual FoxPro 8.0 Professional Edition, Microsoft Visual FoxPro 9.0 Professional Edition

  • KB98434
Feedback