Richard Gibbins (12/14/2009)
To see what happened when there is a null value, I tried:
declare @txt varchar(255)
set @txt = 'Question'
insert xxx values ('')
select @txt = isnull (a, '?') from xxx order by i
and got a null string and not "?" as I was expecting.
In SQL Server, an empty string and a NULL value are not the same.
It can be shown by this:
create table #xxx (i int identity, a varchar(3))
declare @txt varchar(255)
set @txt = 'Question'
insert #xxx values ('')
select @txt = isnull (a, '?') from #xxx order by i
select @txt -- the result is '' (empty string)
insert #xxx values (null)
select @txt = isnull (a, '?') from #xxx order by i
select @txt -- the result is '?'
select @txt = a from #xxx order by i
select @txt -- the result is NULL
drop table #xxx
and this:
declare @var varchar(255)
set @var = ''
if @var is null select 'NULL' else select 'NOT NULL' -- the result is 'NOT NULL'
set @var = null
if @var is null select 'NULL' else select 'NOT NULL' -- the result is 'NULL'
As far as I know, NULLs and empty strings are equal in Oracle. But in SQL Server they are not.