Here are the basic steps you take to define a scalar function:
- Define the SQL_TEXT constant.
For more information, see SQL_TEXT Definition.
- Include the sqltypes_td.h header file.
For more information, see Header Files.
- Include other header files that define macros and variables that the function uses.
- Define the function parameter list in the order that matches the parameter passing convention specified in the CREATE FUNCTION statement.
For more information, see Scalar Function Parameter List.
- Implement the function and set the result to the appropriate value.
- If the function detects an error, set the:
-
sqlstate argument to an SQLSTATE exception or warning condition before the function exits.
For more information, see Returning SQLSTATE Values.
- error_message string to the error message text. The characters must be inside the LATIN character range. The string is initialized to a null-terminated string on input.
-
sqlstate argument to an SQLSTATE exception or warning condition before the function exits.
- If the function uses parameter style SQL, set the indicator_result argument.
IF the result is … THEN set the indicator_result argument to … NULL -1. not NULL 0.