During the AGR_FINAL aggregation phase, a UDF produces the final result for the group. The function must set the result argument to the final value.
The storage area pointed to by interim1 in the FNC_Context_t argument points to the aggregate storage area for the group. The function uses the interim1 pointer to calculate the final value and return it in the result argument.
In the standard deviation example, the function can use the following statements to calculate the final value:
FLOAT term2 = s1->x_sum / s1->n; FLOAT variance = (s1->x_sq / s1->n) - (term2 * term2);
The following statement sets the result argument to the final value of the standard deviation:
*result = sqrt(variance);