Inserting global variables into SQL queries

In an SQL query you can reference objects and create conditions for selecting data fields. By combining the search criterion WHERE with a variable, the content of the variable is used as the search string.

To insert a global variable into an SQL query:

  1. Create the SQL select statement SELECT * FROM Products
  2. Enter a search condition at the end of the statement using WHERE. Specify a data field that the search condition refers to. For example: SELECT * FROM Products WHERE SupplierId
  3. If a variable is used, the SQL statement is evaluated as a formula. This requires that the statement must be enclosed in double quotation marks (") and be preceded with an equals sign (=). The variable must be enclosed in double quotation marks and ampersands. For example:="SELECT * FROM products WHERE supplierid ="&globalvariables.supplierid.text&"" .
    If the variable produces a string value instead of a numerical value, it (and the double quotes that already surround it) must be enclosed in single quotes (’). For example:="SELECT * FROM products WHERE productname ='"&GlobalVariables.ProductName.text&"'"