VALUE

The VALUE statement declares global values.  It exists in two forms: the full form used to declare global values and a short form that omits the expression.  

 

VALUE @<value> <type> = <expression>

VALUE @<value> <type>

 

Examples

 

VALUE @deg2rad FLOAT64 = Pi / 180;

 

VALUE @angle FLOAT64 = 30;

 

VALUE @anglerad FLOAT64 = @angle * @deg2rad;

 

In the above, a type is required. The type can be TABLE.  A global variable can be redefined and assigned a different type and value. When this happens, previous references to the global variable will continue to use its former type and value,  similar to what happens when overriding functions.

 

Short form example

 

VALUE @name NVARCHAR;

 

The short form of VALUE takes an existing value and converts it to the specified type. If there is no value with the specified name defined, the short form defines it and sets it to a NULL value.  The short form is useful for handling query parameters.

 

Additional Examples

Add a computed field that uses a global value:

 

ALTER TABLE t (

  ADD d INT32

    WITH [[ VALUE @mul INT32 = 500; ]]

    AS [[ a * @mul ]]

);

 

Add a constraint that uses a global value:

 

ALTER TABLE t (

  ADD CONSTRAINT a_c

    WITH [[ VALUE @min INT32 = 0; ]]

    AS [[ a>=@min ]]

);

 

 

Notes

Functions are their own world - Functions are their own world when it comes to parameters.   All references to parameters inside a function body are resolved to local parameters, that is, to parameters explicitly passed as arguments to that function.  

 

VALUE @deg2rad FLOAT64 = Pi / 180;

FUNCTION rad_1(@deg FLOAT64) FLOAT64 AS @deg * @deg2rad END;

 

In the above query fragment, the function rad_1 would cause an error (and shown in red text to emphasize it is incorrect) because it uses @deg2rad, a parameter that has not been declared as an argument.   

 

VALUE @deg2rad FLOAT64 = Pi / 180;

FUNCTION rad_2(@deg FLOAT64, @convert FLOAT64) FLOAT64 AS @deg * @convert END;

 

SELECT * FROM [TABLE] WHERE [angle] > rad_2(45, @deg2rad);

 

The function rad_2 will work in the query above, because all parameters used within the function are declared as arguments.

 

See Also

Queries

 

Command Window

 

Query Builder

 

SQL Statements

 

EXECUTE

 

GROUP BY

 

SPLIT

 

TABLE

 

UNION / EXCEPT / INTERSECT

 

VALUES