Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding heading spaces to string data

Posted on 2012-04-02
2
Medium Priority
?
431 Views
Last Modified: 2012-04-02
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!
0
Comment
Question by:sevior
2 Comments
 
LVL 18

Accepted Solution

by:
Dave Ford earned 2000 total points
ID: 37797209
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
 

Author Comment

by:sevior
ID: 37797526
Thanks,
it works:

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

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question