Off the top of my head I would probably do something like
select replace(space(len(PortionKey)),' ','_')
In hindsight, I ought to explain this...
I generated a load of space characters (space
]) based on the length of the column (len
That meant that I knew exactly what I wanted to replace