Environment & System Variables - Embedding Parameters in SQL Code

Changing the Value of Environment Variables in Run-Time

The value of Environment Variables can be changed and updated in the Container Manager, or immediately before code that contains variables is executed in run-time: Changes made in the Container Manager are saved in the Properties of each Environment (see Changing the Value of Variables in the Container Manager for info), whereas changes made before code is executed are not saved and are only used for execution.

Note: The value of variables can be changed in run-time when running a script (or query) against a Container in the editor, or when deploying code packages. In other words, if you are running code in a connected editor window (i.e., against a single database), you cannot assign values to variables in run-time yet you can still change values after previewing the script code.

The following examples demonstrate how to change variables value in run-time. Here, assume that two Environment Variables are defined for the Development environment in the Container Manager, namely TableOwner and LinkedServerName. These variables are used in the following script, which will be executed against the Web Databases container (under the Development environment).

Figure 102.7:  Sample script that uses Environment Variables.

After pressing F5 to run the script against the Web Databases container, Combine prompts the following dialog, which allows you to set the value of your variables. To update a value, select the variable in the drop-down or double-click the variable entry in the dialog, enter the new value, and then press the Update button. When done, press OK to continue with the execution.

Figure 102.8:  Updating variable values in run-time when all variables are valid.

The status of all the variables in the example above (see Fig. 102.8) is Valid. In other words, all variables were previously defined for the Environment against which the code is executed. However, in some cases, the status of variables may be invalid due to one of two reasons: (i) The variable is not defined for the Environment; (ii) No value is associated with the variable in the Container Manager. The following example demonstrates invalid Environment Variables.

As before, assume that two variables are defined under the Development environment, namely TableOwner and LinkedServerName. Next, the following code that contains an undefined variable called MyUndefinedVariable is executed.

Figure 102.9:  SQL script that contains an undefined variable.

When the code is executed against a Container or as part of a code package, Combine prompts the following dialog. Here, the undefined variable is marked as Invalid. In this dialog, you can update the value of the invalid (and other valid) variables, and then continue with the execution.

Figure 102.10:  Updating variable values in run-time when some variables are invalid.

© 2001-2017 JNetDirect, Inc. All Rights Reserved.