Difference between IsNumeric and Try_Parse inbuilt function in SQL-Server.

Posted by vishalneeraj-24503 under SQL Server category on | Points: 40 | Views : 1412
Try_Parse is a new in-built function introduced in SQL-Server 2012.

The problem with IsNumeric is that, we can not get the exact value which is passed as an expression meaning that it returns only 1 and 0. If expression is number then it return 1 else returns 0.

So, Try_Parse is introduced in SQL-Server 2012.

We can understand this 2 by an example:-

1). select isnumeric('1234') as [1234],isnumeric(1234) as [1234],isnumeric('1234sddd') as [1234];

2). select try_parse('1234' as int) as '1234',try_parse('1234.000' as int) as '1234',try_parse(.as1234n.000' as int) as '1234';

Output will be:-
1). 1,1,0
2). 1234,1234,Null

As, we can see that in isnumeric it's returning 1 for valid number but in try_parse it's returning same number,if it's number and returns null if not a number.

Comments or Responses

Login to post response