RSS Feed

TRY_PARSE()

TRY_PARSE()

TRY_PARSE(): It is a method that will lead in bringing a result of an expression, casted to the specified data type and if the cast fails then return null. This method relies on .Net’s CLR (i.e. Common Language Runtime).

Syntax of TRY_PARSE():

TRY_PARSE ( string_value AS data_type [ USING culture ] )

Example of TRY_PARSE():

IF (TRY_PARSE('11/05/2012' AS DATETIME) IS NULL)
BEGIN
 PRINT 'NULL';
END
ELSE 
BEGIN
 PRINT 'NOT NULL';
END
Result will be NOT NULL.

For complete post go to SQL Server 2012 Enhancements.