strange behaviour of null in sql

Today i came across a problem while writing stored procedures , i wrote a query containing union as follows
select col1, col2, col3 from tablename1 a into temptable
union
select col1,col2,col3 from tablename2

then i wrote a query check a col1 is not present in another table called tablename3

select * from temptable where col1 not in ( select col1 from tablename3)

strangely it does not return any thing i checked whether select statements returning any thing or not
they are returning well
then i wrote a condition to check null
select isnull(col1,'99999'0 from tablename3
then it returned the values
coz the tablename3 col1 first row has null value so its not returning any thing if we have not checked for null

Comments

Popular Posts