ToScalar

Use the ToScalar function to explicitly return a scalar (single) value from a result set.

Syntax

ToScalar(<expression>)

The expression parameter can be any xSQL command that generates a result set.

Return Type

Varies

Details

The function improves code readability by making the developer’s intention explicit when setting variables to single values.  Recall, variables can store entire results sets in addition to single (scalar) values.

If the result set returns more than one column or row, the function will return the value found in the first column and row of the result set.

Examples

ToScalar() in the following example is optional, but using the function clearly indicates that the developer only expects the variable, v_period_name, to be assigned a single value (vs. an entire multi-column and multi-row result set).

set v_period_name *= ToScalar(select name 
			from xactly.xc_period 
			where LookupPeriodTypeByPeriodName(name) = 'MONTHLY'
			and '2016-04-01' between start_date and end_date);

toscalar_01

Related Functions

Set

Eval