Convert GUID to varchar(32)

孤街醉人 提交于 2019-12-05 12:37:17

问题


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.

  1. Table1.colx is a GUID so it is 36 characters in length in total due to the hyphens
  2. 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.


回答1:


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


来源:https://stackoverflow.com/questions/16222343/convert-guid-to-varchar32

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!