TRYCAST takes a string and tries to cast it to a data type specified after the AS keyword (similar to CAST). If the conversion fails, TRYCAST returns a NULL instead of failing.
The result of the conversion is returned unless there is an error, in which case a NULL is returned. The result data type is whatever data type was specified by the data_type input.
TRYCAST ( instring AS data_type )
- A CHAR or VARCHAR expression in the LATIN or UNICODE character set.
- One of the following supported data types:
- CHAR (LATIN or UNICODE)
- VARCHAR (LATIN or UNICODE)
- TIME (with zone)
- TIMESTAMP (with zone)
- All INTERVAL types