How do I check if a SQL Server text column is empt

2019-01-16 05:37发布

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 compare against '' yields this response:

The data types text and varchar are incompatible in the not equal to operator.

Is there a special function to determine whether the value of a text column is not null but empty?

15条回答
做自己的国王
2楼-- · 2019-01-16 06:04

I know this post is ancient but, I found it useful.

It didn't resolve my issue of returning the record with a non empty text field so I thought I would add my solution.

This is the where clause that worked for me.

WHERE xyz LIKE CAST('% %' as text)
查看更多
Juvenile、少年°
3楼-- · 2019-01-16 06:08

I would test against SUBSTRING(textColumn, 0, 1)

查看更多
够拽才男人
4楼-- · 2019-01-16 06:12

You could do like

SELECT * FROM TABLE WHERE FIELDNAME=''
查看更多
霸刀☆藐视天下
5楼-- · 2019-01-16 06:13

Use the IS NULL operator:

Select * from tb_Employee where ename is null
查看更多
相关推荐>>
6楼-- · 2019-01-16 06:14

Actually, you just have to use the LIKE operator.

SELECT * FROM mytable WHERE mytextfield LIKE ''
查看更多
狗以群分
7楼-- · 2019-01-16 06:15
ISNULL(
case textcolum1
    WHEN '' THEN NULL
    ELSE textcolum1
END 
,textcolum2) textcolum1
查看更多
登录 后发表回答