Trim function in V7.1
Posted in 1995
Hi all,
Is there any function or combination of functions in V7.1 SQl that will take a
character string and if it is full of spaces convert it to NULL as part of an
insert statement?
I have looked at the length and the trim functions but cannot work out a way of
combining them to get the desired result. I had considered something like this
trim(trailing length(t1) from t1) but length returns 0 on an empty string and I
can't see any function call that would return null or space depending on the
size of t1.
There is a workaround that would use a stored procedure expression that would
return null if the string passed to it was full of spaces. Eg:
insert into test1 values (trimnull(t1));
create procedure trimnull(t1 char(44) returning varchar(44);
if length(t1) = 0 then
return NULL;
else
return trim(t1);
end if;
end procedure;
But this has two major problems. One I expect the performance will be hit
badly as this will need to be interpreted for each field. Second I would need
several of these as some of the chararacter strings which I need to convert to
null are converted to other datatypes, such as decimal, integer and datetime,
by the database so I would need special ones handling char strings of the
correct length.
Cheers - Jim
--
-----------------------------------------------------------------------------
Jim Gordon DHL Airways Inc. jgordon@us.dhl.com
-----------------------------------------------------------------------------
My opinions are my own. They may vary with time but they remain mine!