Getting around the “Conversion failed … uniqueidentifier” error

I was trying to find the unique ID of a Smurf in my appropriately named Smurf table. ID was a GUID, so I thought I would run a query like so:

SELECT * FROM Smurf WHERE ID = ’80A17BC9-AA8C-4588-B59D-00011FD411D0′

But Gargamel thwarted me with this error:

 Msg 8169, Level 16, State 2, Line 2  Conversion failed when converting from a character string to uniqueidentifier.

Bummer, my Smurfs were stuck. But luckily, the solution for my stuck Smurfs wasn’t too difficult, I just has to convert the string to a uniqueidentifier:

SELECT * FROM Smurf WHERE ID = CONVERT(uniqueidentifier,’80A17BC9-AA8C-4588-B59D-00011FD411D0′)

And there they were, in all their Smurfy goodness.



  1. #1 by Dana Brackett on September 13, 2016 - 11:54 am

    I don’t have a smurf table, but adapted your code to mine…and I still get the error…..HELP!!

    • #2 by scottstoecker on September 15, 2016 - 4:15 pm

      What is the error? And is the value you are checking a valid GUID?

Leave a Reply

Fill in your details below or click an icon to log in: 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

%d bloggers like this: