I am using SQL Server 2005. I have a table with a text column and I have many rows in the table where the value of this column is not null, but it is empty. Trying to comp
Use the IS NULL operator:
Select * from tb_Employee where ename is null
DECLARE @temp as nvarchar(20)
SET @temp = NULL
--SET @temp = ''
--SET @temp = 'Test'
SELECT IIF(ISNULL(@temp,'')='','[Empty]',@temp)
try this:
select * from mytable where convert(varchar, mycolumn) = ''
i hope help u!
Actually, you just have to use the LIKE operator.
SELECT * FROM mytable WHERE mytextfield LIKE ''
Instead of using isnull
use a case
, because of performance it is better the case.
case when campo is null then '' else campo end
In your issue you need to do this:
case when campo is null then '' else
case when len(campo) = 0 then '' else campo en
end
Code like this:
create table #tabla(
id int,
campo varchar(10)
)
insert into #tabla
values(1,null)
insert into #tabla
values(2,'')
insert into #tabla
values(3,null)
insert into #tabla
values(4,'dato4')
insert into #tabla
values(5,'dato5')
select id, case when campo is null then 'DATA NULL' else
case when len(campo) = 0 then 'DATA EMPTY' else campo end
end
from #tabla
drop table #tabla
You have to do both:
SELECT * FROM Table WHERE Text IS NULL or Text LIKE ''