Page 1 of 1

char to varchar

Posted: Fri Oct 05, 2007 11:55 am
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

Posted: Fri Oct 05, 2007 12:13 pm
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)

Posted: Fri Oct 05, 2007 2:33 pm
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")

Posted: Mon Oct 18, 2010 3:46 am
by synsog
Simple and perfect solution. Very helpful :D

Posted: Mon Oct 18, 2010 4:28 am
by ray.wurlod
Thank you. It was simple (and presumably helpful) three years ago too.