TRY_CONVERT Function - SQL


Overview


The TRY_CONVERT function in SQL attempts to convert an expression to a specified data type. If the conversion is successful, it returns the converted value; otherwise, it returns NULL.

Example:

SELECT TRY_CONVERT(10, CHAR(2))

Syntax:

SELECT TRY_CONVERT(expression, target_data_type)

expression is the value to convert from one data type to another.

target_data_type is the data type to which you want to convert the expression.