How can I query out the empty field in may database. I tried using "select * from table where field = '' " But It doesn't work! I'm still returned with a field with no value in it. And I'm pretty sure the field with no value in it is not null.
If it is a not null field then it would be storing spaces depending on the datatype char/varchar. It also depends on a few ansi settings.
Following will help you in most of the cases:
------------
select * from table
where datalength(isnull(rtrim(myField),' ')) = ' '
------------
Thanks guys for answering my query. But it still doesn't work Raj and so is the replace Claire. The empty field contains 30 spaces (the data type of the field is a Char and has a length of 30).
Does the empty field contain 30 space characters or is it null...
If T-SQL try...
<CODE>
SELECT DISTINCT
*
FROM
Table
WHERE
MyField IS NULL
OR
LTRIM(RTRIM(MyField)) = ''
GO
</CODE>
...to look for both, or take out one or other of the CLAUSES.
Rhys
Thought out... Maybe,
Opinionated... Probably
But it is only an opiniion!
HI Rhys, Thanks for answering,I tried what you said and it still doesn't work. Claire and Rhys, the fields is not null nor '', I think the field contains 30 spaces. I was able to determine this by retrieving the field in vb and using the lenght function (LEN) and it gave me 30. So the fields contains 30 spaces or whatever but it's definetely not null.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.