HOWTO: Passing Variables to SELECT-SQL w/o Using Macro Substitution

Article translations Article translations
Article ID: 114670 - View products that this article applies to.
This article was previously published under Q114670
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

SUMMARY

When you are passing variables to a SELECT - SQL command, you may have to call the command and programmatically pass criteria to it rather than coding such criteria directly. In many such instances, you may not want to use macro substitution.

The programs below show how to pass variables to a SELECT - SQL command without using macro substitution.

MORE INFORMATION

The programs below are provided as an example of calling a FoxPro SELECT - SQL command with the selection criteria contained in variables. They employ name expressions and the EVALUATE function instead of macro substitution.

FoxPro 2.x Example

*This program uses the Customer table from the Tutorial.
SET TALK OFF     && stop echo to screen
x="State"
y="FL"
SELECT * ;
   FROM customer;
   HAVING EVALUATE(x) = (y) ;
   INTO CURSOR crsrFlorida
BROWSE
				

Visual FoxPro Example

*!* This sample uses the Customer table in:
*!* VFP 3/5 -- HOME() + "Samples\Data"
*!* VFP 6 -- HOME(2) + "Data"

SET TALK OFF     && stop echo to screen
x="Country"
y="UK"

SELECT * ;
   FROM CUSTOMER;
   HAVING EVALUATE(x)=(y);
   INTO CURSOR crsrUK
BROWSE
				
The output will contain records where the contents of the field whose name is contained in variable x are equal to the contents of variable y.

Properties

Article ID: 114670 - Last Review: February 28, 2014 - Revision: 2.2
APPLIES TO
  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 6.0 Professional Edition
  • Microsoft FoxPro 2.5b
  • Microsoft FoxPro 2.6 Standard Edition
  • Microsoft FoxPro 2.5b for MS-DOS
  • Microsoft FoxPro 2.6 for MS-DOS
  • Microsoft FoxPro 2.5b for Macintosh
Keywords: 
kbnosurvey kbarchive kbhowto KB114670

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com