Defining a query with variables

About this task

In the Database Interface Designer Query dialog, variables can be specified in SQL statements as literals enclosed in pound sign (#) characters. For example, you might enter a statement that defines a variable named ID:

select * from BigTable where Identifier = #ID#

Because the value of a variable may be a text string, you can also create larger elements of the statement variable. For example:

select * from BigTable where #WhereClause#

When you define variables in a query, the Database Interface Designer automatically detects the presence of the variables in the statement and lists each variable in the Navigator, along with a variable icon.

Use the Define Variables dialog to enter the variable values. Note that you cannot generate a type tree for the query until you have specified a value for each variable it contains. Also, if the variable you are defining in the Define Variables dialog is a text string, you must enclose the value in single quotation marks.

The pseudo values specified using the Define Variables dialog are used in the Database Interface Designer only when accessing the database to generate the type tree. They are not used when executing a map.

To specify values in the Define Variables dialog

Procedure

  1. In the Navigator, select the variable to which you want to add one or more values.
  2. From the Query menu, select Define Variables.
    The Define Variables dialog appears, listing all the variables in the MDQ file.
  3. In the Value field, enter a value for each variable and click OK.
    The pseudo values are stored in the MDQ file and can only be changed in the Define Variables dialog. Also, if the variable you are defining is a text string, you must enclose the value in single quotation marks.

To delete a variable

About this task

When a variable is removed from a query statement that was previously defined in the Database Interface Designer, the variable is automatically deleted from the Navigator and no longer displays.