Portal | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
gauravgupta2808
Warnings : 1

New User

Joined: 31 May 2007
Posts: 31
Location: Chennai, India

 Posted: Wed Oct 17, 2007 5:37 pm    Post subject: Convert Integer to Char while selecting in a DB2 query 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.

Srihari Gonugunta

Active User

Joined: 14 Sep 2007
Posts: 295
Location: Singapore

 Posted: Wed Oct 17, 2007 5:52 pm    Post subject: Gaurav, Try DIGITS function
gauravgupta2808
Warnings : 1

New User

Joined: 31 May 2007
Posts: 31
Location: Chennai, India

 Posted: Wed Oct 17, 2007 6:03 pm    Post subject: Reply to: Convert Integer to Char 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.
Srihari Gonugunta

Active User

Joined: 14 Sep 2007
Posts: 295
Location: Singapore

 Posted: Thu Oct 18, 2007 1:00 pm    Post subject: 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
gauravgupta2808
Warnings : 1

New User

Joined: 31 May 2007
Posts: 31
Location: Chennai, India

 Posted: Mon Oct 22, 2007 9:12 pm    Post subject: Reply to: Convert Integer to Char while selecting in a DB2 q 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
Srihari Gonugunta

Active User

Joined: 14 Sep 2007
Posts: 295
Location: Singapore

 Posted: Tue Oct 23, 2007 3:27 pm    Post subject: Gaurav, Glad to know that it helped you...
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics How do i verify the char field is hav... Raghu M N PL/I & Assembler 1 Tue Sep 22, 2020 9:26 pm To convert numeric to Packed Decimal vinu78 DFSORT/ICETOOL 9 Fri Jul 31, 2020 7:14 pm how to convert Hex String t char hex Martylin PL/I & Assembler 6 Fri Jun 05, 2020 7:45 pm Mainframe ISPREDIT Macro query upendrasri TSO/ISPF 3 Wed May 27, 2020 1:12 pm Insert System Runtime in HEADER In SY... Rick Ryan SYNCSORT 9 Tue May 26, 2020 9:01 pm

 © 2003-2020 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us