SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Null check for GUID data type
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

susan_151615
Yak Posting Veteran

India
99 Posts

Posted - 06/15/2009 :  00:30:12  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 06/15/2009 :  01:17:40  Show Profile  Visit webfred's Homepage  Reply with Quote
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)

Singapore
17627 Posts

Posted - 06/15/2009 :  01:18:46  Show Profile  Reply with Quote

where employee.empid is null



KH
Time is always against us

Go to Top of Page

susan_151615
Yak Posting Veteran

India
99 Posts

Posted - 06/15/2009 :  01:40:33  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 06/15/2009 :  01:53:09  Show Profile  Visit webfred's Homepage  Reply with Quote
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

India
99 Posts

Posted - 06/15/2009 :  01:58:11  Show Profile  Reply with Quote
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)

Singapore
17627 Posts

Posted - 06/15/2009 :  02:00:03  Show Profile  Reply with Quote
isnull(convert(varchar(36), empid ), '')



KH
Time is always against us

Go to Top of Page

susan_151615
Yak Posting Veteran

India
99 Posts

Posted - 06/15/2009 :  02:09:26  Show Profile  Reply with Quote
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)

Singapore
17627 Posts

Posted - 06/15/2009 :  02:11:14  Show Profile  Reply with Quote
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
Time is always against us


Edited by - khtan on 06/15/2009 02:11:33
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 06/15/2009 :  11:46:52  Show Profile  Reply with Quote
Maybe you want to do something like:
COALESCE(empid, CAST('00000000-0000-0000-0000-000000000000' AS UNIQUEIDENTIFIER))
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000