Removing leading or trailing tabs...

Database
Enthusiast

Removing leading or trailing tabs...

I want to remove leading and trailing tabs in a column... I tried trim function and its not working... is there any other means we can remove the leading or trailing tabs...

5 REPLIES
Senior Supporter

Re: Removing leading or trailing tabs...

you can use a simple substr 

like 

case when substr(cola,1,1) = '\t' then substr(cola,2) else cola end

for leading

'\t' need to be replaced with a tab...

and 

case when characters(cola) = 1

                 then case when cola = '\t' then '' else cola end

        else   case case when substr(cola,charcaters(cola),1) = '\t' then substr(cola,1,characters(cola)-1) else cola end

end

if you are on 13.1 make SQL UDFs out of this to have nicer code

Senior Supporter

Re: Removing leading or trailing tabs...

And check also 

http://developer.teradata.com/blog/madmac/2010/03/a-few-basic-scalar-string-udfs

there are some very useful udfs...

Junior Contributor

Re: Removing leading or trailing tabs...

Or just use TRIM(BOTH '09'xc FROM col)

Dieter

Senior Supporter

Re: Removing leading or trailing tabs...

:-) - yes, this is nice, I always forget this option in trim...

Enthusiast

Re: Removing leading or trailing tabs...

Thanks Dieter.. it works like charm... I am new to teradata... will u please tell me whats this option means ('09'xc)... what are the other values that we can use it in here...

Ulrich your method didnt yield the expected results...