如何在 SQL Server 2005 中识别空白的 uniqueidentifier?

发布于 2024-08-16 05:52:48 字数 367 浏览 3 评论 0原文

我将一个 uniqueidentifier 放入一个看起来像这样

00000000-0000-0000-0000-000000000000 的存储过程中。

这看起来很简单,但是如何识别这是一个空白的uniqueidentifier呢?

如果我得到这样的值 DDB72E0C-FC43-4C34-A924-741445153021 我想做 X

如果我得到这样的值 00000000-0000-0000-0000-000000000000 > 我做 Y

有没有比计算零更优雅的方法?

提前致谢

I'm getting a uniqueidentifier into a Stored Procedure that looks like this

00000000-0000-0000-0000-000000000000.

This seems like a simple thing, but how can identify that this is a blank uniqueidentifier?

If I get a value like this DDB72E0C-FC43-4C34-A924-741445153021 I want to do X

If I get a value like this 00000000-0000-0000-0000-000000000000 I do Y

Is there a more elegant way then counting up the zeros?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

不离久伴 2024-08-23 05:52:48

比较

cast(cast(0 as binary) as uniqueidentifier)

compare to

cast(cast(0 as binary) as uniqueidentifier)

?

只是在用心讲痛 2024-08-23 05:52:48

只需创建一个 EmptyGuid 变量并与之比较:

DECLARE @EmptyGuid UniqueIdentifier
SET @EmptyGuid = '00000000-0000-0000-0000-000000000000'

Just create an EmptyGuid variable and compare against that:

DECLARE @EmptyGuid UniqueIdentifier
SET @EmptyGuid = '00000000-0000-0000-0000-000000000000'
_畞蕅 2024-08-23 05:52:48
IF (@TheGuid = '00000000-0000-0000-0000-000000000000')
    SELECT 'Do Y'
ELSE
    SELECT 'Do X'
IF (@TheGuid = '00000000-0000-0000-0000-000000000000')
    SELECT 'Do Y'
ELSE
    SELECT 'Do X'
﹉夏雨初晴づ 2024-08-23 05:52:48

最好的解决方案是对空 GUID 使用常量

DECLARE @EmptyGuid UNIQUEIDENTIFIER
SET @EmptyGuid = '00000000-0000-0000-0000-000000000000'

,或者

DECLARE @EmptyGuid UNIQUEIDENTIFIER
SET @EmptyGuid = 0x0

您只需比较它们

IF @parameter = @EmptyGuid
    DO Y
ELSE
    DO X

注意:您不需要使用强制转换和转换

Best solution is to use a constant for the empty GUID

DECLARE @EmptyGuid UNIQUEIDENTIFIER
SET @EmptyGuid = '00000000-0000-0000-0000-000000000000'

OR

DECLARE @EmptyGuid UNIQUEIDENTIFIER
SET @EmptyGuid = 0x0

and you just compare them

IF @parameter = @EmptyGuid
    DO Y
ELSE
    DO X

Note: you don't need to use casts and converts

王权女流氓 2024-08-23 05:52:48

这也有效。

DECLARE @EmptyGuid UNIQUEIDENTIFIER = CONVERT(UNIQUEIDENTIFIER, 0x0);  
SELECT @EmptyGuid

This also works.

DECLARE @EmptyGuid UNIQUEIDENTIFIER = CONVERT(UNIQUEIDENTIFIER, 0x0);  
SELECT @EmptyGuid
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文