NULLS

 

if object_id('tempdb..#temp') is not null
   	drop table #temp
 
go

create table #temp (
	 ID int not null identity(1,1)
	,Name varchar(50) null
	,constraint temp_PK primary key clustered (ID)
)

go


insert into #temp (Name) values ('Ed')
insert into #temp (Name) values ('Kim')
insert into #temp (Name) values (NULL)
insert into #temp (Name) values ('')

go


--
-- logical commands on a null return null and are never TRUE. Called tri-state logic
--

select *
	from #temp

select *
	from #temp
	where Name = NULL

select *
	from #temp
	where Name != NULL

go


--
-- use IS NULL instead
--

select *
	from #temp
	where Name is null

select *
	from #temp
	where Name is not null

go

--
-- the isnull() function can be useful (but hard on query optimization)
--

select *, isnull(Name, '')
	from #temp
	where isnull(Name, '') = ''

go