Sql 查询,选择唯一标识符给出 - 将数据类型 varchar 转换为 uniqueidentifier 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6022603/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 10:34:17  来源:igfitidea点击:

Sql query, selecting on unique identifier gives - Error converting data type varchar to uniqueidentifier

sqlsql-server

提问by dev.e.loper

How do I select a column of type uniqueidentifier when I have a guid?

当我有一个 guid 时,如何选择类型为 uniqueidentifier 的列?

I've tried doing following:

我试过做以下事情:

SELECT * FROM MyTable WHERE id = '442402e-207d-b012-4b60-005056c00123'

and 

SELECT * FROM MyTable WHERE id = '{442402e-207d-b012-4b60-005056c00123}'

Both give me same error: Error converting data type varchar to uniqueidentifier.

两者都给我同样的错误:将数据类型 varchar 转换为 uniqueidentifier 时出错。

回答by Lamak

The first query is ok, but you are missing a digit on the first part of the GUID, it should have 8 digits, not seven....something like this:

第一个查询没问题,但是您在 GUID 的第一部分缺少一个数字,它应该有 8 位数字,而不是 7 位....像这样:

SELECT * FROM MyTable WHERE id = '71494DD6-90FB-417D-B9E2-28F34103C039'

回答by Albin Sunnanbo

You are missing a digit in the first section

您在第一部分中缺少一个数字

4067876A-E3C3-4A3D-B2D3-E879474168C6is a valid GUID
442402e-207d-b012-4b60-005056c00123is not

4067876A-E3C3-4A3D-B2D3-E879474168C6是有效的 GUID
442402e-207d-b012-4b60-005056c00123不是