O'Reilly logo

What's New in SQL Server 2012 by Jon Reade, Rachel Clements

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Conversion functions

SQL Server 2012 introduces some useful conversion functions that will help you avoid errors when dealing with different data types. We will use easy-to-understand examples so you can see how beneficial they are.

TRY_PARSE

TRY_PARSE doesn't look too useful on surface, but as we will soon see it has a vey useful specialist niche.

The basic syntax of TRY_PARSE is as follows:

SELECT TRY_PARSE (string AS datatype)

Each of the following will return a NULL, as the value passed in the string does not convert to a value of the data type specified as the second parameter:

SELECT TRY_PARSE ('SQL Server 2012' AS datetime) AS MyDateTime SELECT TRY_PARSE ('SQL Server 2012' AS decimal) AS MyDecimal SELECT TRY_PARSE ('ABC' AS float) AS MyFloat ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required