Wednesday, October 31, 2012

null is not nothing

Let's assume we have a table @a  Do you think

select * from @a
where a = a


is the same as writing
select * from @a

?

Well, think at it for a second before reading furher. Now run this code
declare @p as varchar(5) = null
declare @A as table (a varchar(5))
insert into @A values ('a1')
insert into @A values ('a2')
insert into @A values ('a3')
insert into @A values (null)
select * from @a where a = ISNULL(@p, a)

Why ? hmm, there is a nice discussion about DB NULL values here. And in many many other places on the web

No comments: