Trim of varchar

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
subrat
Premium Member
Premium Member
Posts: 77
Joined: Tue Dec 11, 2007 5:54 am
Location: UK

Trim of varchar

Post by subrat »

Hello

Just need a small clarification...

I have a field (lets suppose COL_A) which is of CHAR data type. I changed it to VARCHAR in a later stage.

Now if i am passing a values with leading or trailing zeros and using trim function[TRIM(COL_A)] on it, then what would be output of COL_A.

Is the leading and trailing zeros will removed?
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

Leading and trailing zeros will not be removed, unless you specifically ask them to be removed.

The syntax TRIM(COL_A) will trim only white space. To remove the leading zeros i think the syntax is TRIM(COL_A,'L',0') although I could have the L and the 0 around the wrong way. Similarly there is option for removing trailing characters.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

actually 'L' and '0' should be placed other way.

trim(COL_A,'0','L') which will remove only the leading zeros.

to remove leading and trailing zeros use

trim(COL_A,'0','B')
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

Thought as much - didn't have a system handy to check. Thanks for the correction though.
zhzhs
Participant
Posts: 13
Joined: Mon Nov 13, 2006 10:40 pm
Location: china

Re: Trim of varchar

Post by zhzhs »

TRIM(COL_A,"0","L") is right, i have tried it.
I have a baby
dsscholar
Premium Member
Premium Member
Posts: 195
Joined: Thu Oct 19, 2006 2:45 pm

Re: Trim of varchar

Post by dsscholar »

For char function only trim is needed right, do we need to use it for varchar function also.. As varchar will take exactly the space required for the character.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You can still have trailing characters (including spaces) in a varchar that need to be removed, but don't fall into the trap of trying to trim trailing spaces from a char.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply