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.
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.
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.
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.
Convert the uniqueidentifier to varchar:
CAST( uniqueidentifier_col_name as varchar)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With