Let's assume we have a table @a Do you think
where a = a
is the same as writing
?
Well, think at it for a second before reading furher. Now run this code
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