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!? ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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> Can anyone tell me how right justification can be done in string</div> <div> </div> <div> </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-- |
| |||
| 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 |
| |||
| 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 |
| ||||
| 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 |