Microsoft – SQL Server – IsGuid Function
A few weeks ago, I “paced” the Internet looking for an “IsGUID” Function.
We had a table that has a column defined as a UniqueIdentifier (GUID) and inserts were failing when invalid (un-fully baked) GUIDs were passed in.
So in SQL we have a couple of functions such as IsNumeric and IsDate that validate date. But, no built-in function for validating GUIDs.
Luckily I found a good function on the .Net.
And, that book was closed, a bit. But, really did have it at the back of mind.
Today reading look another blog led me to Bob Beauchemin’s SQLSkills Blog:
How excited could one be that MS is adding a couple of functions to Transact SQL:
These functions are added to Denali (MS SQL Server v2012).
The Parse and Try-Parse functions are a bit restrictive as they only allow “parsing” to a limited set of datatypes.
On the other hand, the Try_cast and Try_Convert are more generic and do not restrict conversion choices to a well defined, limited, set of datatypes.
Try_Convert like Convert allows one to specify a Style type.
- Parse ( http://technet.microsoft.com/en-us/library/hh213316 )
- Try_Cast ( http://technet.microsoft.com/en-us/library/hh974669 )
- Try_Convert ( http://technet.microsoft.com/en-us/library/hh230993 )
- Try_Parse ( http://technet.microsoft.com/en-us/library/hh213126 )