SQL Select查询中的GUID比较 [英] GUID Comparision in SQL Select Query

查看:318
本文介绍了SQL Select查询中的GUID比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我有一张表,其中的列是 uniqueidentifier 数据类型.在这里,我想选择与uniqueidentifier数据进行比较的记录.

例如:

Dear All,

I have a table with the column of uniqueidentifier Datatype. here i want to select the records compare with the uniqueidentifier data.

Ex:

CREATE TABLE [dbo].[Table1](
    [Id] [uniqueidentifier] NOT NULL,
    [Name] [nvarchar] (100) NOT NULL







SELECT * FROM Table1 WHERE Id <= 'A8912F3C-81BE-4076-B6AB-0000017330AD'



可以选择记录吗?请建议我



It''s possible to select the records? please suggest me

推荐答案

这是一个毫无意义的查询-用Guid术语表示的小于或等于"没有实际意义.哪些记录少于" Guid?实际上,由于未按任何特定顺序发布Guid,因此未定义.下一个Guid问题可以以"2","F"或另一个"A"开头.

不要尝试根据任何顺序比较Guid-这个概念对他们来说毫无意义.

您想做什么,以为与向导一起使用< =会有所帮助?
That is a meaningless query - "less than or equal to" in Guid terms has no real meaning. What records are "less than" a Guid? Undefined, really, since Guids are not issued in any particular order. The next Guid issues could start with a ''2'', or a ''F'', or another ''A''.

Don''t try to compare Guids based on any order - the concept is meaningless for them.

What are you trying to do, that you think "<=" with Guids would be helpful?


如果我错了,其他人将不得不纠正我,但我不正确.不要相信您可以将<=>=运算符与uniqueidentifiers一起使用.

最好的选择是相等运算符:

Others will have to correct me if I''m wrong, but I don''t believe that you can use <= or >= operators with uniqueidentifiers.

Your best bet is the equality operator:

SELECT * FROM Table1 WHERE Id = 'A8912F3C-81BE-4076-B6AB-0000017330AD'



如果要查询一系列唯一标识符,可以使用where.. in 条款:



If you want to query a range of uniqueidentifiers you could use a where.. in clause:

SELECT * FROM Table1 WHERE Id IN ('A8912F3C-81BE-4076-B6AB-0000017330AD', 'B8912F3C-81BE-4076-B6AB-0000017330AD', 'C8912F3C-81BE-4076-B6AB-0000017330AD')


这篇关于SQL Select查询中的GUID比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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