Skip to content

Instantly share code, notes, and snippets.

@jonsagara
Last active December 3, 2023 09:15
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jonsagara/1285011 to your computer and use it in GitHub Desktop.
Save jonsagara/1285011 to your computer and use it in GitHub Desktop.
Generating Guid.Empty in SQL Server
--
-- 2021-11-24: suggestion from comments:
--
DECLARE @EmptyEmpty UNIQUEIDENTIFIER = CAST(0x0 AS UNIQUEIDENTIFIER)
SELECT @EmptyEmpty
--
-- Original
--
DECLARE @EmptyGuid UNIQUEIDENTIFIER
SET @EmptyGuid = (SELECT CAST(CAST(0 AS BINARY) AS UNIQUEIDENTIFIER))
-- Single result is 00000000-0000-0000-0000-000000000000
SELECT @EmptyGuid
@HerbertLins
Copy link

HerbertLins commented Apr 18, 2019

Thanks!

@LuigimonSoft
Copy link

Nice!!!

@mihail-shishkov
Copy link

mihail-shishkov commented Aug 28, 2019

Even simpler

DECLARE @EmptyGuid UNIQUEIDENTIFIER = 0x0
SELECT @EmptyGuid

Or

SELECT * FROM Table WHERE GuidColumn = 0x0

@Fagro
Copy link

Fagro commented Nov 12, 2019

2 cents:

select cast(0x0 as uniqueidentifier)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment