Difference between PARSE() and TRY_PARSE() functions

 Posted by Bandi on 9/4/2013 | Category: .NET Framework Interview questions | Views: 4492 | Points: 40
Answer:

PARSE(), TRY_PARSE() functions are introduced in the SQL Server 2012..
Difference: While attempting to PARSE any column, if you get one or more incorrect values, PARSE function will throw an error. However, if you use TRY_PARSE function, it will not throw error but will return the result as NULL

Ex:
1) SELECT PARSE('249.000' AS INT) AS ParseAsInt

This will return result as 249

2) SELECT PARSE('A249.000' AS INT) AS ParseAsInt throws ERROR because of invalid data
SELECT TRY_PARSE('A249.000' AS INT) AS ParseAsInt returns NULL


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response

More Interview Questions by Bandi