Solved

Adding heading spaces to string data

Posted on 2012-04-02
2
373 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:
daveslash earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now