Set
Summary
The SET
command sets a variable to a command or expression in the Connect environment. Use variables in other XSQL and DCL commands and expressions.
Syntax
set <variable_name> = <command or expression>; set <variable_name> *= <command or expression>; |
Parameters
Parameter
|
Description
|
---|---|
<variable_name> |
The name of the variable. |
<command or expression> |
The command or expression to assign to the variable. |
Details
The variable can be set to any valid command or expression. If the command or expression evaluates to a scalar value, you can use the variable in any XSQL command where a scalar value is appropriate. If the evaluated value is a result set, you can use the variable in XSQL commands where a table name is appropriate.
The =
operator assigns the definition of the command or expression to the named variable. A variable’s expression is evaluated at run time when referenced in another XSQL command using the variable/parameter syntax described in this section, or when an EVAL
command is executed, not when the variable is set. This is similar to how Microsoft Excel computes values after you assign a formula to a cell.
The variable identified by <variable_name>
is a global variable available for use in any XSQL command. Variables are available across all Connect sessions. Connect does not support local variables.
Conversely, the *=
operator assigns the value of the expression to the variable immediately when set. XSQL statements that reference variables set with *=
do not evaluate the expression at run time. The evaluated value typically ends up being a constant following evaluation. In cases when the expression returns a result set, the value is a scalar value representing the first row and first column.
The difference between =
and *=
is subtle, but has functional and performance implications.
Exercise care when changing the definition of a globally shared variable.
Also, avoid recursive or circular references within the command or expression since this results in an error when evaluating the expression (similar to Microsoft Excel).
Examples
set a = 5 ; set a = select Min(hire_date) from xactly.xc_participant; set a = b / 5 ; set a *= a + 1 ; //The following command examples illustrate the difference between using the '=' and '*=' operators. Note the timestamps. set v_now_dynamic = Now(); eval v_now_dynamic; //run the eval a few times. set v_now_static *= Now(); eval v_now_static; //run the eval a few times. |
Related Commands