Convert GUID to varchar(32)

guid, sql, sql-server, ssms, varchar

Solution

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)),'-','')

Problem

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. - Table1.colx is a GUID so it is `36` characters in length in total due to the hyphens - The corresponding column is table2.colx but it is a VARCHAR(32) I 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.

Original source