Unix Technical Forum

String Right justification

This is a discussion on String Right justification within the Informix forums, part of the Database Server Software category; --> Hi, Can anyone tell me how right justification can be done in string Regards Nirmala __________________________________________________ Do You Yahoo!? ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2008, 12:18 PM
Nirmala Kesavan
 
Posts: n/a
Default String Right justification

Hi,
Can anyone tell me how right justification can be done in string


Regards
Nirmala

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-20-2008, 12:18 PM
bozon
 
Posts: n/a
Default Re: String Right justification

In esql there are procedures to manipulate strings that include this
capability. In stored procedure you'll have to do it this way.


<<<< pseudo code >>>>
rightJustify(string str,int width)
let spaces=" " ; //spaces has 255 spaces or what ever the max width
will be.
let len = length(str);
if (len >= width) {
let ret = str;
}
else {
let ret = substr(spaces,1,width - length) || str ;
}

return ret;


Nirmala Kesavan wrote:
> Hi,
> Can anyone tell me how right justification can be done in string
>
>
> Regards
> Nirmala
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> --0-24551121-1149746772=:46256
> Content-Type: text/html; charset=iso-8859-1
> Content-Transfer-Encoding: 8bit
> X-Google-AttachSize: 348
>
> <div>Hi,</div> <div>&nbsp; Can anyone tell me how right justification can be done in string</div> <div>&nbsp;</div> <div>&nbsp;</div> <div>Regards</div> <div>Nirmala </div><p> __________________________________________________ <br>Do You Yahoo!?<br>Tired of spam? Yahoo! Mail has the best spam protection around <br>http://mail.yahoo.com
> --0-24551121-1149746772=:46256--


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-20-2008, 12:19 PM
macgillivary
 
Posts: n/a
Default Re: String Right justification

Does the LPAD function do what you are after?
http://publib.boulder.ibm.com/infoce...c/sqls1037.htm

for example to right justify to 50 characters (padding with spaces):
SELECT LPAD(myfield,50,' ')
FROM mytable

or dynamically based on lengthiest field
SELECT LPAD(myfield,(SELECT max(length(myfield)) FROM mytable),' ')
FROM mytable

Not sure how optimal that last statement would be on a large table.

Not really sure what you are after from your original question.

amg.


Nirmala Kesavan wrote:
> Hi,
> Can anyone tell me how right justification can be done in string


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-20-2008, 12:20 PM
bozon
 
Posts: n/a
Default Re: String Right justification

LPAD is a nice way to do it. You can substitute in my code the lpad
command.

macgillivary wrote:
> Does the LPAD function do what you are after?
> http://publib.boulder.ibm.com/infoce...c/sqls1037.htm
>
> for example to right justify to 50 characters (padding with spaces):
> SELECT LPAD(myfield,50,' ')
> FROM mytable
>
> or dynamically based on lengthiest field
> SELECT LPAD(myfield,(SELECT max(length(myfield)) FROM mytable),' ')
> FROM mytable
>
> Not sure how optimal that last statement would be on a large table.
>
> Not really sure what you are after from your original question.
>
> amg.
>
>
> Nirmala Kesavan wrote:
> > Hi,
> > Can anyone tell me how right justification can be done in string


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-20-2008, 12:20 PM
=?iso-8859-1?q?Rich_or_Krist=EDn?=
 
Posts: n/a
Default Re: String Right justification

Nirmala Kesavan wrote:
> Hi,
> Can anyone tell me how right justification can be done in string
>
>
> Regards
> Nirmala



SELECT SUBSTR(LPAD(someColumn,10,' '),-10,10) FROM myTable;

In this example I've justified the string with spaces and ensured the
total length of the returned string will be 10, I'll leave it to you to
make it more generic etc. but there's more than enough to get you
started ;-)

Rich

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:06 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com