views:

127

answers:

3

Hello

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

+10  A: 

compare to

cast(cast(0 as binary) as uniqueidentifier)

?

davek
My friend you are genius!
codingguy3000
Elegant. +1 to you Sir.
Meff
+2  A: 

Just create an EmptyGuid variable and compare against that:

DECLARE @EmptyGuid UniqueIdentifier
SET @EmptyGuid = '00000000-0000-0000-0000-000000000000'
Eric Petroelje
+2  A: 
IF (@TheGuid = '00000000-0000-0000-0000-000000000000')
    SELECT 'Do Y'
ELSE
    SELECT 'Do X'
LukeH