Skip to main content

Using Advanced Expressions: Try_Cast

Distributor guide to the TRY_CAST advanced expression in Encompass Fusion reports: convert a value to another data type, returning NULL instead of an error. Needs FusionEdit permission and v23.01+.

B
Written by Bailey Naas-Thornton

Minimum Version Required: 23.01

Pre-Conditions

  • Required Permission - FusionEdit
    ​
    ​

  • Recommended Fusion I/II Certification

Steps

Try_Cast is a special version of the CAST function that is available for a subset of data type conversions. It performs the same operation (i.e converts a value of one data type into another data type), but returns a NULL value instead of raising an error when the conversion can not be performed.
​
​

Syntax

TRY_CAST(source_string_expr AS target_data_type)


​
​Arguments

source_string_expr:

string value to try casting to another data type


​target_data_type:

must be one of the following: VARCHAR, NUMBER, DOUBLE, BOOLEAN, DATE, TIME, TIMESTAMP, TIMESTAMP_LTZ, TIMESTAMP_NTZ, or TIMESTAMP_TZ


​
​Example

TRY_CAST('abc' AS NUMBER) = NULL

TRY_CAST('123' AS NUMBER) = 123

Did this answer your question?