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
 ISNULL behavior

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-04-12 : 09:54:57
Will ISNULL treat an empty string the same as a null string?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-12 : 10:11:06
No, it won't, as demonstrated by the example below:
DECLARE @x VARCHAR(32);
SET @x = '';
SELECT ISNULL(@x,'Aha! It is NULL');

If you do want it to be null, you can nest the NULLIF function:
DECLARE @x VARCHAR(32);
SET @x = '';
SELECT ISNULL(NULLIF(@x,''),'Aha! It is NULL');
Nullif will ignore trailing spaces:
DECLARE @x VARCHAR(32);
SET @x = ' '; --spaces
SELECT ISNULL(NULLIF(@x,''),'Aha! It is NULL');
Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-04-12 : 10:37:27
Wow. This is disturbing. I was given the exact opposite answer from the powers-that-be around me. i guess "question authority" still applies.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2012-04-12 : 11:28:04
Or...Trust but verify.
Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-04-12 : 11:55:04
that's why i hang out here.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-04-17 : 04:34:14
In ORACLE emptry string is equal to NULL

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -