The information in this article applies to:
SUMMARYUsing macro substitution or wildcards in a SELECT-SQL statement allows the data to be defined, extracted, and accessed dynamically.
MORE INFORMATIONThe following program example uses macro substitution to dynamically change the query output generated by the SELECT-SQL statement. The macro substitution is in the SQL WHERE clause. CLEAR ACCEPT "Enter a two character state " TO M_State M_Cust_St = "UPPER(customer.state)" M_EQ = "=" M_State = "'"+UPPER(M_State)+"'" M_Key = M_Cust_St + " " + M_EQ + " " + M_State SELECT customer.company, customer.contact, customer.state ; FROM customer ; WHERE &M_Key ; INTO CURSOR EX_SQL BROWSE TIMEOUT 10 DISPLAY MEMORY LIKE M_* NOTE: When you are using macro substitution for the entire SELECT-SQL statement in a stand-alone executable file, for example mselect = "SELECT * FROM CUSTOMER" &mselect the macro must be addressed before the macro or command is translated. To resolve this issue and avoid possible errors, include the necessary source code in a separate procedure file in the project prior to compiling the executable file, as shown in the following program example: PROCEDURE NotUsed SELECT customer.company, customer.contact, customer.state ; FROM customer ; WHERE customer.state = "NC" ; INTO CURSOR EX_SQL If the NotUsed procedure is NOT added to the project, the user will receive a "Feature not available" error message at run time. mwhere = "STATE = 'NC'" SELECT * FROM CUSTOMER WHERE &mwhere the NotUsed procedure is NOT required. SELECT * ; FROM customer,invoices ; WHERE customer.cno = invoices.cno ; INTO CURSOR EX_SQL1 BROWSE TIMEOUT 10 Optionally, you can use a wildcard with a work area alias by entering the filename, a period, and then an asterisk. The following SELECT-SQL statement contains all fields used in the CUSTOMER file (which is suffixed with an asterisk); the CNO and SALESMAN fields are displayed as output from the INVOICES.DBF file for all records that contain matching CNO keys in both files. SELECT customer.*,invoices.cno,invoices.salesman ; FROM customer,invoices ; WHERE customer.cno = invoices.cno ; INTO CURSOR EX_SQL2
REFERENCESFoxPro for MS-DOS "Developer's Guide," version 2.0, page D16-11 Additional query words: FoxMac FoxDos FoxWin memvar wild card Keywords : FxprgSql Version : 2.50 2.50a 2.50b | 2.00 2.50 2.5 Platform : MACINTOSH MS-DOS WINDOWS Issue type : |
Last Reviewed: August 24, 1999 |