SQL 将 GUID 转换为 varchar(32)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16222343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert GUID to varchar(32)
提问by Jfabs
How can I convert a GUID which is 36
characters to a VARCHAR(32)?
如何将36
字符的 GUID 转换为VARCHAR(32)?
I'm trying to copy data from one table to another. There are two similar columns from these two tables.
我正在尝试将数据从一张表复制到另一张表。这两个表中有两个相似的列。
- Table1.colxis a GUID so it is
36
characters in length in total due to the hyphens - The corresponding column is table2.colxbut it is a VARCHAR(32)
- Table1.colx是一个 GUID,因此
36
由于连字符,它的总长度为字符 - 对应的列是table2.colx但它是一个 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.
我正在寻找一种将 GUID 转换为 VARCHAR 的方法,但我必须删除连字符。到目前为止,我试图找到一种方法来做到这一点没有成功。
回答by Esoteric Screen Name
I assume this is SQL Server, from the SSMS tag.
我假设这是来自 SSMS 标记的 SQL Server。
Convert the GUID to a string, then replace the hyphens with empty strings:
将 GUID 转换为字符串,然后用空字符串替换连字符:
REPLACE(CAST(table1.colx AS VARCHAR(36)),'-','')