Converts data types into other data types based on specified parameters. If the conversion cannot be performed, CAST returns an error. To return a NULL value instead, use TRY_CAST.
Syntax
Parameters
| Parameter | Description | Supported input types |
|---|
<value> | The value to convert or an expression that results in a value to convert. | Any |
<type> | The target data type (case-insensitive) | Any |
Return Types
Same data type as <type>
Example
The following example returns 1 as an integer:
SELECT CAST('1' AS INTEGER) AS level;
Rows: 1Execution time: 4.93ms
CAST can also be done by writing the format before the object, for example - SELECT DATE '2022-01-01' , SELECT TIMESTAMP '2022-01-01 01:02:03'.