Author |
Message
|
chenna.hari |
Posted: Wed May 15, 2013 9:42 pm Post subject: adding leading zeroes in esql |
|
|
Centurion
Joined: 21 Mar 2009 Posts: 103
|
Hi,
I need to generate the output always 3 characters, with adding leading 0's if the length of the input is less than 3 characters.
eg. input is 1, then output should be 001
input is 12, then output should be 012
input is 123, then output should be 123.
Can any one suggest the best way to do this in esql.
Regards,
Hari. |
|
Back to top |
|
 |
marko.pitkanen |
Posted: Wed May 15, 2013 9:46 pm Post subject: |
|
|
 Chevalier
Joined: 23 Jul 2008 Posts: 440 Location: Jamsa, Finland
|
Have you modeled the output message? |
|
Back to top |
|
 |
PEPERO |
Posted: Wed May 15, 2013 9:47 pm Post subject: |
|
|
Disciple
Joined: 30 May 2011 Posts: 177
|
try this way :
Set strWithleftPaddedZeros = SUBSTRING('000' from 1 for (3 - LENGTH(originString))) || originString;
you could also use the 'RIGHT' command. |
|
Back to top |
|
 |
dogorsy |
Posted: Wed May 15, 2013 9:51 pm Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
|
Back to top |
|
 |
chenna.hari |
Posted: Wed May 15, 2013 9:52 pm Post subject: |
|
|
Centurion
Joined: 21 Mar 2009 Posts: 103
|
No, Ouput message is not modeled. |
|
Back to top |
|
 |
kash3338 |
Posted: Thu May 16, 2013 10:01 pm Post subject: |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
You can make use of OVERLAY function. Thats a easy way of doing this. |
|
Back to top |
|
 |
dogorsy |
Posted: Thu May 16, 2013 10:10 pm Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
kash3338 wrote: |
You can make use of OVERLAY function. Thats a easy way of doing this. |
I cannot see how overlay is easier than
CAST((cast input_field as integer) as char format '000');
or RIGTH('000'||input_field,3); |
|
Back to top |
|
 |
|