Quick one today:
Years ago, there was a popular comment that Sql Server did not wide variety of functions; Once of them is the much needed IsNumeric functionality. Though such a function existed, there was a case where it resulted in incorrect results. So there were several custom functions like IsReallyNumeric or IsInteger, etc (my personal DBA library also had such custom functions)
Now, there is a powerful function that does more than just IsNumeric capability. It is called TRY_PARSE. Let’s take an example:
-- -- Sample code for TRY_PARSE -- SELECT TRY_PARSE('ABCDEF' AS INT) AS [INT_Test1] , TRY_PARSE('123456' AS INT) AS [INT_Test2] , TRY_PARSE('ABCD-01-01' AS DATETIME) AS [DateTime_Test1] , TRY_PARSE('2016-01-01' AS DATETIME) AS [DateTime_Test2] GO
This function takes input in VARCHAR/NVARCHAR format and attempts to convert into the requested format. If the result is successful, the value is returned in requested data type. If not, NULL is returned. This makes it very useful in data processing logic flows; And makes it more useful function than the legacy (IsNumeric) functions.