Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Null check for GUID data type

Author  Topic 

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2009-06-15 : 00:30:12
Hi I have a column which is of GUID type and of nullable type.
I need to do null check for this column of guid type.
Is this the proper way to do null check for GUID data type:

IsNUll(employee.empid,NULL)here empid is a GUID value

susan

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-15 : 01:17:40
No that is not to check if empid is null it is to replace the value of empid in case of null.
select isnull(empid,666) would return 666 if empid is null for example.

The check would be
IF empid IS NULL
or
WHERE empid IS NULL

Greetings
Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-15 : 01:18:46
[code]
where employee.empid is null
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2009-06-15 : 01:40:33
Suppose i want to return it blank value then how to replace it in null check because it will not accept the replacement with '' as it is not varchar it throws error during execution

susan
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-15 : 01:53:09
Can you show us an example in context what you're trying to do please?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2009-06-15 : 01:58:11
this is what am trying to do

select
ISNULL(EMPLOYEE.EMPNAME,'') AS EMPLOYEE NAME,
EMPLOYEE.EMPID AS EMPLOYEEID
INTO #EMP

here empname is varchar and empid is guid type and how to do null check for this guid type

susan
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-15 : 02:00:03
[code]isnull(convert(varchar(36), empid ), '')[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

susan_151615
Yak Posting Veteran

99 Posts

Posted - 2009-06-15 : 02:09:26
No guid cant be converted into varchar type it will be not compatible in front end processotr even though it can be executed in sql

susan
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-15 : 02:11:14
quote:
Originally posted by susan_151615

No guid cant be converted into varchar type it will be not compatible in front end processotr even though it can be executed in sql

susan



then handle the NULL value in your front end not in the query


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-06-15 : 11:46:52
Maybe you want to do something like:
COALESCE(empid, CAST('00000000-0000-0000-0000-000000000000' AS UNIQUEIDENTIFIER))
Go to Top of Page
   

- Advertisement -