View previous topic :: View next topic
|
Author |
Message |
gauravgupta2808 Warnings : 1 New User
Joined: 31 May 2007 Posts: 31 Location: Chennai, India
|
|
|
|
Hi,
I need to convert an integer to char while selecting in a DB2 query.
I have used CHAR(integer), but the problem with this is that it removes the leading zeroes from the integer.
Ex : If integer = 01001 then i get CHAR(integer) = 1001.
But i need to retain the leading zeroes.
Can you please help me with this. |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
Gaurav,
Try DIGITS function |
|
Back to top |
|
|
gauravgupta2808 Warnings : 1 New User
Joined: 31 May 2007 Posts: 31 Location: Chennai, India
|
|
|
|
Hi Srihari,
Thanks for the suggestion.
But DIGITS function is adding more leading Zeroes.
If the value of integer = 010004 DIGITS(integer) = 0000010004
If value of integer = 504045, DIGITS(integer) = 0000504045
I donot want the extra zeroes ....
Could you please suggest some way out. |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
Hi Gaurav,
Try the following things.
1) SUBSTR(DIGITS(integer),5,6)) .....only when you are sure that your column always contain 6 digits
2) CAST(Integer as CHAR(10)) this holds good for your case, I suppose.
Please try and let us know if you face some problem |
|
Back to top |
|
|
gauravgupta2808 Warnings : 1 New User
Joined: 31 May 2007 Posts: 31 Location: Chennai, India
|
|
|
|
Thanks Srihari...
Option 1 works...
Option 2 removes the leading zeroes, but in my case i required the leading zero..... As i do a concatenate also
Thank you so much |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
Gaurav,
Glad to know that it helped you... |
|
Back to top |
|
|
|