Re: nulls
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Mar 2007 21:01:24 +0100
On 21 Mar 2007 00:32:20 -0700, othellomy@xxxxxxxxx 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
.
- References:
- Prev by Date: Re: Accessing external data from SQL Server
- Next by Date: Re: help with parameter in WHERE
- Previous by thread: Re: nulls
- Next by thread: Help needed creating select statement
- Index(es):
Relevant Pages
|