Link Search Menu Expand Document

CAST

Similar to TRY_CAST, CAST converts data types into other data types based on the specified parameters. If the conversion cannot be performed, CAST returns an error. To return a NULL value instead, use TRY_CAST.

Syntax

CAST(<value> AS <type>)
Parameter Description
<value> The value to convert or an expression that results in a value to convert. Can be a column name, a function applied to a column or another function, or a literal value.
<type> The target data type (case-insensitive).

Example

SELECT CAST('1' AS INT) as res;

Returns: 1

CAST can also be done by using the :: operator. For more information, see :: operator for CAST.