TRY_CONVERT() SQL Server Example – Screenshot

Leave a comment (0) Go to comments

SQL Server Denali CTP3 has introduces a new function TRY_CONVERT() to evaluates whether a data type conversion is possible or not?

TRY_CONVERT(), checks whether typecasting / datatype conversion from one datatype to other datatype is possible or not and if it possible then it converts the source data type into the target type and if the conversion is not possible then it returns NULL.

How to use TRY_CONVERT() in SQL Server ?

TRY CONVERT() SQL Server Example   Screenshot SQL Server Denali TRY CONVERT sql server 2011 2012 TRY CONVERT How to use TRY CONVERT in SQL Server

In above example, we tried to covert a string ‘test’ into float, which is not possible and NULL is returned by TRY_CONVERT().

-- Another Example of TRY_CONVERT()

Select Try_Convert(DateTime,'19910902') As DATE_TIME_CONVERSION

Select Try_Convert(Numeric(10,4),'19910902') As DECIMAL_CONVERSION

result from the above query



EOF - TRY_CONVERT() SQL Server Example – 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.