How can I convert a GUID which is 36
characters to a VARCHAR(32)?
I'm trying to copy data from one table to another. There are two similar columns from these two tables.
36
characters in length in total due to the hyphensI am looking for a way to convert a GUID to VARCHAR, but I've got to remove the hyphens. So far I have been unsuccessful in my attempts to find a way to do this.
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.
Uniqueidentifier is a Microsoft SQL Server data type that is used to store Globally Unique Identifiers (GUIDs). It can store 16 bytes of data. The Developer tool treats the Uniqueidentifier data type as String. To move or change Uniqueidentifier data, connect the Uniqueidentifier column to a String column.
LOWER() function in SQL Server This function in SQL Server helps to convert all the letters of the given string to lowercase. If the given string contains characters other than alphabets, then they will remain unchanged by this function. Parameters : str – The string which will be converted to lowercase.
I assume this is SQL Server, from the SSMS tag.
Convert the GUID to a string, then replace the hyphens with empty strings:
REPLACE(CAST(table1.colx AS VARCHAR(36)),'-','')
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