fairoakian
asked on
Empty varchar is not null
I've been inserting a textarea field from a form into a varchar field. This textarea field is empty most of the time, but the field in the database is not null. When I run a len() on the fields that look blank I get numeric values ranging from 2 to 10, so there is some kind of data in there even though I can't see anything and the textarea was blank.
Going forward I am using validation on the front end to insert them specifically as null, but I'd like to be able to go clean up the table and make them all null because I'm now trying run a case statement off that field.
Going forward I am using validation on the front end to insert them specifically as null, but I'd like to be able to go clean up the table and make them all null because I'm now trying run a case statement off that field.
you could do this:
select * from table
where len(lrtrim(rtrim(fieldname ))) = 0 or fieldname is null
select * from table
where len(lrtrim(rtrim(fieldname
it must be some special characters
just try
SELECT LEN( LTRIM(RTRIM(urColumn)) )
from urTable
Also u can get the ascii value of first characters on those columns by using
select ASCII (urColumnName)
from urTable
just try
SELECT LEN( LTRIM(RTRIM(urColumn)) )
from urTable
Also u can get the ascii value of first characters on those columns by using
select ASCII (urColumnName)
from urTable
ASKER
Thank you. I tried all three solutions and the value returned is identical to using just the len function.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ya, it gave me a 13 for the empty fields.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
that seems to be strange
try this one two
select ASCII (LTRIM(urColumnName) )
from urTable
try this one two
select ASCII (LTRIM(urColumnName) )
from urTable
ASKER
Splitting points as aneeshattingal came up with the test and angelIII proposed the solution.
UPDATE SomeTable
SET SomeColumn = NULL
WHERE LTRIM(SomeColumn) = ''