Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql query, selecting on unique identifier gives - Error converting data type varchar to uniqueidentifier

Tags:

sql

sql-server

How do I select a column of type uniqueidentifier when I have a guid?

I've tried doing following:

SELECT * FROM MyTable WHERE id = '442402e-207d-b012-4b60-005056c00123'

and 

SELECT * FROM MyTable WHERE id = '{442402e-207d-b012-4b60-005056c00123}'

Both give me same error: Error converting data type varchar to uniqueidentifier.

like image 693
dev.e.loper Avatar asked May 16 '11 19:05

dev.e.loper


1 Answers

The first query is ok, but you are missing a digit on the first part of the GUID, it should have 8 digits, not seven....something like this:

SELECT * FROM MyTable WHERE id = '71494DD6-90FB-417D-B9E2-28F34103C039'
like image 166
Lamak Avatar answered Sep 29 '22 14:09

Lamak