TRY_PARSE() – SQL Server Function usage with Screenshot

Leave a comment (0) Go to comments

SQL Server Denali CTP3 has introduces a new function TRY_PARSE() to translate the result of an expression to specified data type.

TRY_PARSE() tries to translate the result of an expression to specified data type if the translation is possible, otherwise, it returns NULL. Moreover, we can also specify the CULTURE, during this conversion.

CULTURE, means a language (English, Japanese, Spanish, Danish, French etc.) which will used by SQL Server to interpret data.

HOW to use TRY_PARSE() in SQL Server ?

TRY PARSE()   SQL Server Function usage with Screenshot SQL Server Denali TRY PARSE sql server 2011 2012 TRY PARSE How to use TRY PARSE in SQL Server

another example,

SELECT TRY_PARSE('18' AS datetime2)
--  Returned NULL

GO

SELECT TRY_PARSE('18' AS NUMERIC(18,2))
-- Returned 18.00

GO

By using this TRY_PARSE() function, we can avoid errror, "Conversion failed when converting the varchar value ‘DBATAG’ to data type int.", where we are unsure about the values.


NOTE :

  • TRY_PARSE is only used for converting from string to date/time and number types.
  • If the server does not have the CLR installed, this function will fail

For More Information check Microsoft BOL

EOF - TRY_PARSE() – SQL Server Function usage with Screenshot, SQL Server 2012 , 2008 R2 , 2008 , 2005 , 2000

Leave a Reply

Your email address will not be published. Required fields are marked *


*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.