473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Right Align the character field Value

Hi,

column nme: TEMP
Datatype: CHAR length: 6

the value we are getting is

TEMP
2X ,
SWD ,
1QER ,
What we want is

00002X,
000SWD,
001QER

Basically we want to rigth align the fields firstand then replace the
spaces by zeros.

Regards,
Pioneer

Jan 12 '06 #1
5 13468
Pioneer wrote:
Hi,

column nme: TEMP
Datatype: CHAR length: 6

the value we are getting is

TEMP
2X ,
SWD ,
1QER ,
What we want is

00002X,
000SWD,
001QER

Basically we want to rigth align the fields firstand then replace the
spaces by zeros.


Have a look at the REPEAT, CONCAT, and LENGTH functions.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Jan 12 '06 #2
Pioneer wrote:
Hi,

column nme: TEMP
Datatype: CHAR length: 6

the value we are getting is

TEMP
2X ,
SWD ,
1QER ,
What we want is

00002X,
000SWD,
001QER

Basically we want to rigth align the fields firstand then replace the
spaces by zeros.

Thsi should do:
SUBSTR((SUBSTR('000000', 1, 6 - LENGTH(RTRIM(TEMP)))) || TEMP, 1, 6)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
DB2 UDB for Linux, Unix, Windows
IBM Toronto Lab
Jan 12 '06 #3
This should work:

RIGHT('000000'||RTRIM(CHAR(your_column_here)),6)

Jan 12 '06 #4
This will work:

RIGHT('000000'||RTRIM(CHAR('XXX')),6)

Vijayk
Pioneer wrote:
Hi,

column nme: TEMP
Datatype: CHAR length: 6

the value we are getting is

TEMP
2X ,
SWD ,
1QER ,
What we want is

00002X,
000SWD,
001QER

Basically we want to rigth align the fields firstand then replace the
spaces by zeros.

Regards,
Pioneer


Jan 12 '06 #5
There's lots of ways of doing this:

select temp,substr(right('000000' concat rtrim(temp),6),1,6) from t1

select temp,right('000000' concat rtrim(temp),6) from t1

Excluding the first column of the output; the first yields a 6 byte
result column. The second outputs 6 bytes for each row but the 6 bytes
is in a 4k varchar column, the length of the output of the right
function. If you run these through the command prompt, then the second
will output 4k long rows.

Phil Sherman
Pioneer wrote:
Hi,

column nme: TEMP
Datatype: CHAR length: 6

the value we are getting is

TEMP
2X ,
SWD ,
1QER ,
What we want is

00002X,
000SWD,
001QER

Basically we want to rigth align the fields firstand then replace the
spaces by zeros.

Regards,
Pioneer

Jan 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: praba kar | last post by:
Dear all, Is it possible to right align the Ipaddress? Normally we can right align the list of numbers by %3u or %7u. How we can right align the Ipaddress? I expects below format output...
11
by: Markus Mueller | last post by:
Hi, I'm using a form with a bunch of input tags to enter numbers. Is there any way to make the input field right adjusted, so that the numbers align at the right side instead of the left? Even...
3
by: kai | last post by:
Hi, All When I place a label on a Web form, label text is always left align, I cannot find the property to set right align. Any way to set align property for the label text to right align? ...
3
by: Wardeaux | last post by:
I need to right align the text in a textbox (or label) in my ASP.NET app... Any clues best way to accomplish this? MTIA wardeaux
2
by: Hans Kesting | last post by:
Hi, Can I right-align a number with leading *spaces*? F.i. I have the value 2 and I want to display it as " 2". int num = 2; string s = num.ToString("00"); // gives "02", but I don't want the...
4
by: Steve Swift | last post by:
If it is possible, could someone demonstrate how to make the text entered into an <INPUT TYPE=TEXTfield right-align within the entry field, please? The fields in my form are for numbers, and...
3
by: nk215 | last post by:
Hello I have a regular expression question. Here's what I want to do change TEST RADIUS 123.254 to TEST RADIUS 3.25
1
by: David Greenberg | last post by:
Hi I have a character field (char ot varchar) that I want to force only to contain numeric characters. Can that be done by way of defining a constraint on the field ? or by any other way in the...
3
by: Indrajit Chakraborty | last post by:
I am developing a simple web site in ASP. I have a web page which has a form, and I want to set the values of two text box to 2 fields selected by a query. One of the fields is a name field which has...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.