thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Intermediate

TRY_CAST Function

A conversion function that returns NULL instead of raising an error when the value cannot be converted.

Definition

TRY_CAST is available in SQL Server, Azure SQL, Snowflake and Databricks SQL. It is useful when loading or cleansing messy text data, letting a query flag bad values rather than fail. Related variants include TRY_CONVERT and TRY_TO_NUMBER.

Example

SELECT TRY_CAST('abc' AS INT); -- returns NULL

Exam tip

Choose TRY_CAST when a scenario says to keep the query running despite invalid values.

Related terms