Reply to Re: nulls

Your name:

Reply:


Posted by Hugo Kornelis on 03/21/07 20:01

On 21 Mar 2007 00:32:20 -0700, othellomy@yahoo.com wrote:

(snip)
>SET @a = ''
>SET @b = ' '
>if nullif(@a,'') is null and nullif(@b,'') is null
> PRINT 'They are equal!';
>ELSE
> PRINT 'They are different!';

Hi othellomy,

I'm not sure what you're trying to say here. This code will return "They
are equal!" if both @a and @b are either NULL or a string consisting of
zero or more space characters, regardless of whether they are equal:

DECLARE @a varchar(10), @b varchar(10);
SET @a = ' ';
SET @b = NULL;

if nullif(@a,'') is null and nullif(@b,'') is null
PRINT 'They are equal!';

But it will return nothing if @a and @b are both non-NULL and not empty,
even if they ARE equal:

DECLARE @a varchar(10), @b varchar(10);
SET @a = 'X';
SET @b = @a;

if nullif(@a,'') is null and nullif(@b,'') is null
PRINT 'They are equal!';

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация