The TRY_CONVERT Function
The TRY_CONVERT
function available in SQL Server 2012 is similar to the TRY_PARSE
function in that if the conversion is successful, it returns the value as the specified data type. Otherwise, it returns a NULL
value. However, if you request a conversion that is explicitly not permitted, TRY_CONVERT
fails with an error.
Like CONVERT
, TRY_CONVERT
can handle converting to data types other than integer or date and time values.
Get Microsoft® SQL Server 2012 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.