char to 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
ds_is_fun
Premium Member
Premium Member
Posts: 194
Joined: Fri Jan 07, 2005 12:00 pm

char to varchar

Post by ds_is_fun »

We had issues in moving data from char to varchar fields. I have trimmed all char before writing to varchar. Is there anything else I should be looking at? thx
michaeld
Premium Member
Premium Member
Posts: 88
Joined: Tue Apr 04, 2006 8:42 am
Location: Toronto, Canada

Post by michaeld »

yah, char will pad all unused bytes with CHAR(0). Trim does not remove them. I use the convert function:

convert(char(0),'',inputcolumn)
Mike
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The three-argument version of Trim() will remove them.

Performance Tip
Initialize a stage variable to Char(0) and do not derive it. That way the Char() function is evaluated only once per run, rather than once per row.

Code: Select all

Trim(InLink.TheString, svNUL, "A")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
synsog
Premium Member
Premium Member
Posts: 232
Joined: Sun Aug 01, 2010 11:01 pm
Location: Pune

Post by synsog »

Simple and perfect solution. Very helpful :D
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Thank you. It was simple (and presumably helpful) three years ago too.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply