|
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]
|