In this article I will discuss about the TRY_PARSE function in SQL Server 2012. Conversion functions helps us avoid errors when dealing with different data types. Let us understand TRY_PARSE with an example.
SELECT TRY_PARSE ('12-18-2013' AS datetime) AS Alpha SELECT TRY_PARSE ('2013' AS decimal) AS Beta SELECT TRY_PARSE ('2013.00' AS decimal) AS Gamma SELECT TRY_PARSE ('2013.0000' AS float) AS Theta SELECT TRY_PARSE ('Arsenal' AS float) AS Delta
The TRY_PARSE() function can convert any string value to a Numeric or Date/Time format. If the passed string value cannot be converted to Numeric or Date/Time format, it will result to a NULL.
Lets have a look at the output of the above
In the above case it would not convert ‘Arsenal’ to a date time or Numeric value and hence it results in NULL output. TRY_PARSE function is not a native SQL SERVER function, instead it is a CLR dependent function.
Tagged: Data type, Functions, Microsoft SQL Server, Null, PARSE, SQL, SQL Server 2012, TRY_PARSE
Leave a Reply