Solved

Adding heading spaces to string data

Posted on 2012-04-02
2
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
Dave Ford 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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

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 (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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

623 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