将GUID转换为varchar(32) [英] Convert GUID to varchar(32)

查看:337
本文介绍了将GUID转换为varchar(32)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将36个字符的GUID转换为VARCHAR(32)?

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 是一个GUID,由于连字符的原因,它的总长度为36个字符
  2. 对应的列是 table2.colx ,但它是VARCHAR(32)
  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)

我正在寻找一种将GUID转换为VARCHAR的方法,但是我必须删除连字符.到目前为止,我一直没有成功找到实现此目标的方法.

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.

推荐答案

我认为这是来自SSMS标记的SQL Server.

I assume this is SQL Server, from the SSMS tag.

将GUID转换为字符串,然后用空字符串替换连字符:

Convert the GUID to a string, then replace the hyphens with empty strings:

REPLACE(CAST(table1.colx AS VARCHAR(36)),'-','')

这篇关于将GUID转换为varchar(32)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆