VARIABLE functions
System variables and scoped variables are used by inserting their values into SQL fragments in the definitions of objects like metrics and filters. The function used to do this is @@VARIABLE, which has the following syntax:
@@VARIABLE(variablename[,"datatype"][,"delimiter"][,"defaultvalue"])
- The variablename and datatype parameter values are case insensitive. The rest is used as-as.
- All parameters, except variablename, are optional. However, to define a parameter that comes after another parameter, you must define the preceding parameter value(s).
- The double quotes (aka string qualifiers) around the parameter values are optional. However, by using double quotes, it allows the delimiter character (, ) to be used in the parameter value.
@@VARIABLE parameters
Parameter | Description |
---|---|
VariableName | The name of the scoped or system variable to look up when resolving its value. |
DataType | Determines whether single quotes are added around the replaced value. The default value ignores this setting and never places single quotes around the value. Valid data types are:
|
Delimiter | The optional delimiter parameter used to concatenate multiple results into a single string value. The default delimiter is a comma (,). The delimiter is only used when the result set of a scoped variable that is using a dynamic expression returns more than one row. This separator can be any string of characters. When using the delimiter parameter, you must define the datatype parameter before it. |
DefaultValue | This is the value that will replace this variable expression when the corresponding variable cannot be found in the hierarchy path or cannot be viewed by the current user when "Apply View permission" is enabled on a scoped variable. By default, an empty string is used when this parameter is not defined. When used, the default value will need to include any surrounding single quotes, since the datatype parameter does not apply to it. |