Partager via


How to: Create Views with Stored SQL Statements

You can use macro substitution to store the SQL SELECT statement created for a view into a variable that you use with the AS clause in the CREATE SQL VIEW command.

To create a view using macro substitution

  1. Create a variable and store the SQL SELECT statement in the variable.

  2. In the AS clause of CREATE SQL VIEW command, use the ampersand (&) macro substitution character followed by the variable name.

For example, the following code stores a SQL SELECT statement into the variable MyEmpCustSQL. CREATE SQL VIEW creates a view named EmpCustView using the variable:

MyEmpCustSQL = "SELECT employee.emp_id, customer.cust_id, ;
   customer.emp_id, customer.contact, customer.company ;
   FROM employee, customer WHERE employee.emp_id = customer.emp_id"
CREATE SQL VIEW EmpCustView AS &MyEmpCustSQL

See Also

Tasks

How to: View and Edit SQL Statements for Views

Reference

CREATE SQL VIEW Command

& Command

Other Resources

Managing Views

Working with Views (Visual FoxPro)