Solved

Adding heading spaces to string data

Posted on 2012-04-02
2
359 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

13 Experts available now in Live!

Get 1:1 Help Now