Conversion Functions
When processing queries, Extreme DPS implicitly converts numeric and character values to the correct types if possible. However, Extreme DPS does not support direct conversions between numeric and character values. To perform conversions from numeric types to character types or from character types to numeric types, conversion functions must be used.
TRY_CAST
Converts an input value to a specified data type. If the conversion fails, NULL is returned.
Syntax
TRY_CAST(<source_expression> AS <destination_type>)
Arguments
-
<source_expression>
The expression that produces to a
varchar
or numeric value that needs to be converted. -
<destination_type>
The destination data type of the conversion.
If
<source_expression>
isvarchar
, then<destination_type>
can be any numeric type; if<source_expression>
is a numeric type, then<destination_type>
can only bevarchar
.
Returns
A value of the destination data type.
Examples
SELECT TRY_CAST('123.45' AS DECIMAL(5,2)) AS converted_value;
-- The result returned is as follows:
converted_value
---------------
123.45