SQL Flow Field Guide

TRY_CAST

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

type conversion

What changes

Input
an expression and target type (and culture/style)
Output or change
converted value (TRY_ variants return NULL on failure)
Return type
Returns a value cast to the specified data type if the cast succeeds; otherwise, returns null.

Syntax at a glance

TRY_CAST ( expression AS data_type [ ( length ) ] )

Work example

Read imperfect imported text without aborting a query when a permitted conversion fails.

Count rejected values separately so null does not silently become accepted data.

Check your work TRY_CAST returns null for a failed permitted conversion but still errors for explicitly disallowed conversions.

Practice SQL

Open in SQL Flow
SELECT TRY_CAST('42' AS int) AS parsed_value, TRY_CAST('four' AS int) AS rejected_value;

Open Microsoft Learn for full syntax, permissions, and details for your version.