Click here to Skip to main content
15,868,164 members
Articles / Database Development / SQL Server
Tip/Trick

How to get an empty GUID in SQL Server

Rate me:
Please Sign up or sign in to vote.
4.23/5 (9 votes)
19 Apr 2011CPOL 119.4K   3   2
A method of comparing with an empty GUID
Sometimes we need to compare a value with an empty GUID in SQL Server, and used to do something like
SQL
myValue = '00000000-0000-0000-0000-000000000000'


But instead of this, we can also do
SQL
select cast(cast(0 as binary) as uniqueidentifier)

and compare with this.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
SuggestionAlternatives Pin
stixoffire17-Sep-15 5:15
stixoffire17-Sep-15 5:15 
How about
select cast((0x0) as uniqueidentifier)
OR simply
Myvalue = NEWID ( )
GeneralNice Pin
I Believe In GOD26-Apr-11 2:03
I Believe In GOD26-Apr-11 2:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.