Nested SQData functions are basically ‘functions within functions’ or a function set. Nesting functions within other functions provides greater flexibility in controlling the data manipulation and logic flow of an SQData Apply Engine script. Some functions, such as CASE, usually result in some level of function nesting.
When using nested functions, it is helpful to put the ending parenthesis for an ‘outer’ function on a separate line and place the ‘inner’ functions within the starting and ending parenthesis.
Example 1
CASE
WHEN SEX = 'M'
{
V_WORKVAR = STRING('MALE')
}
OTHERWISE
{
V_WORKVAR = STRING('FEMALE')
}
In this example, the variable TEMP_VAR is set to ‘MALE’ if the SEX field contains a ‘M’. If the SEX column contains an ‘F’, the variable TEMP_VAR is set to the value ‘FEMALE’. If the SEX column does not contain a ‘M’ or ‘F’, the variable TEMP_VAR is set to the value ‘OTHER’.
Example 2
CASE
WHEN (SEX = 'M' OR SEX = 'F')
{
V_WORKVAR = 'KNOWN')
}
OTHERWISE
{
V_WORKVAR = 'OTHER'
}
In this example, the variable TEMP_VAR is set to ‘KNOWN’ if the SEX field contains either a ‘M’ or ‘F’ value. If the SEX column does not contain a ‘M’ or ‘F’, the variable TEMP_VAR is set to the value ‘OTHER’.
Since a function alias (GENDER_CALC) was specified, this function set can be reused later using the VALUE function.