Hello everyone!
How do I check is argument in SP Empty Guid or not?
Thanks.
Hello everyone!
How do I check is argument in SP Empty Guid or not?
Thanks.
SELECT CAST(CAST(0 AS BINARY) AS UNIQUEIDENTIFIER)
That should return your empty guid.
So to check for that, you would do
IF @GuidParam = CAST(CAST(0 AS BINARY) AS UNIQUEIDENTIFIER)
BEGIN
--Giud is empty
END
Since the empty guid never changes, the other obvious way is to simply use 00000000-0000-0000-0000-000000000000
rather than calculating it.
If @Param = '00000000-0000-0000-0000-000000000000'
...
Or, if in an procedure, you can set a parameter to act as a constant:
Declare @EmptyGuid uniqueidentifier
Set @EmptyGuid = '00000000-0000-0000-0000-000000000000'
Or you could create a scalar user-defined function which simply returns the above constant value (or recalculates it as in Meiscooldude solution).