Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare Varchar and UniqueIdentifier

Due to a rather brilliant oversight in my current project, we have some guids getting stored in a varchar column in one table, which need to be compared to a uniqueidentifier column in another.

How can I do this? SQL server simply says it cannot convert from a character string to a uniqueidentifier.

like image 462
Ed James Avatar asked Aug 10 '09 18:08

Ed James


People also ask

What data type is Uniqueidentifier?

The UNIQUEIDENTIFIER data type is a 16-byte GUID*. This data type is used as primary key alternative to IDENTITY columns. UNIQUEIDENTIFIER is globally unique, whereas IDENTITY is unique within a table. UNIQUEIDENTIFIER values can be generated with NEWID or NEWSEQUENTIALID functions.

What's the difference between Nvarchar and varchar?

The key difference between varchar and nvarchar is the way they are stored, varchar is stored as regular 8-bit data(1 byte per character) and nvarchar stores data at 2 bytes per character. Due to this reason, nvarchar can hold upto 4000 characters and it takes double the space as SQL varchar.

What is data type Uniqueidentifier in SQL?

The globally unique identifier (GUID) data type in SQL Server is represented by the uniqueidentifier data type, which stores a 16-byte binary value. A GUID is a binary number, and its main use is as an identifier that must be unique in a network that has many computers at many sites.


1 Answers

Convert the uniqueidentifier to varchar:

CAST( uniqueidentifier_col_name as varchar)
like image 198
K.A.D. Avatar answered Oct 05 '22 23:10

K.A.D.