Adding heading spaces to string data

Hello experts.
Need your help with modifying data in DB2 table.
The data in one of the columns is like in this example:

abc123
abcd4567
1234abc
1234

so, it's mostly four to eight characters. I would like to add heading "spaces" where strings are less then eight characters (and all values will be 8 chars long), except rows where value IS NULL.

Thank you!
seviorAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Dave FordConnect With a Mentor Software Developer / Database AdministratorCommented:
I think this should do what you're looking for:

select right(repeat(' ', 8) || someData, 8)
  from SomeTable

Open in new window


HTH,
DaveSlash
0
 
seviorAuthor Commented:
Thanks,
it works:

UPDATE MyTab SET MyCol = RIGHT('       'CONCAT TRIM(MyCol),8) where MyCol IS NOT NULL
0
All Courses

From novice to tech pro — start learning today.