Sql Server 2012 many new features to the T-SQL. Some were just added from other languages and platforms to ease the transition to SQL.
Others were added to provide very powerful, new way to solve complex problems
Lets see examples of one of the feature of TRY_CONVERT().
TRY_CONVERT()
Some time CONVERT() and ISNUMERIC() is not always reliable, So values that return are not convertible to all numeric types.
SELECT CONVERT(INT, column1) FROM Temp WHERE ISNUMERIC(column1) = 1
So for above statement sometime that will fail for values like 'abc' which are considered numeric but can not be converted to an integer.
but TRY_CONVERT() will give the result of value 'abc' return NULL instead of returning an error for the entire query.
Syntax:
TRY_CAST ( expression AS data_type [ ( length ) ] )
expression
The value to be cast. Any valid expression.
data_type
The data type into which to cast expression.
length
Optional integer that specifies the length of the target data type.
The range of acceptable values is determined by the value of data_type.
Others were added to provide very powerful, new way to solve complex problems
Lets see examples of one of the feature of TRY_CONVERT().
TRY_CONVERT()
Some time CONVERT() and ISNUMERIC() is not always reliable, So values that return are not convertible to all numeric types.
SELECT CONVERT(INT, column1) FROM Temp WHERE ISNUMERIC(column1) = 1
So for above statement sometime that will fail for values like 'abc' which are considered numeric but can not be converted to an integer.
but TRY_CONVERT() will give the result of value 'abc' return NULL instead of returning an error for the entire query.
Syntax:
TRY_CAST ( expression AS data_type [ ( length ) ] )
expression
The value to be cast. Any valid expression.
data_type
The data type into which to cast expression.
length
Optional integer that specifies the length of the target data type.
The range of acceptable values is determined by the value of data_type.
0 comments:
Post a Comment