Microsoft – SQL Server – IsGuid Function

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:

  • Parse
  • Try_Cast
  • Try_Convert
  • Try_Parse

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.


One thought on “Microsoft – SQL Server – IsGuid Function

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s