Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Convert Integer to Char while selecting in a DB2 query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
gauravgupta2808
Warnings : 1

New User


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

PostPosted: Wed Oct 17, 2007 5:37 pm    Post subject: Convert Integer to Char while selecting in a DB2 query
Reply with quote

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
View user's profile Send private message

Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Wed Oct 17, 2007 5:52 pm    Post subject:
Reply with quote

Gaurav,
Try DIGITS function
Back to top
View user's profile Send private message
gauravgupta2808
Warnings : 1

New User


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

PostPosted: Wed Oct 17, 2007 6:03 pm    Post subject: Reply to: Convert Integer to Char
Reply with quote

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
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Thu Oct 18, 2007 1:00 pm    Post subject:
Reply with quote

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
View user's profile Send private message
gauravgupta2808
Warnings : 1

New User


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

PostPosted: Mon Oct 22, 2007 9:12 pm    Post subject: Reply to: Convert Integer to Char while selecting in a DB2 q
Reply with quote

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 icon_smile.gif
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Tue Oct 23, 2007 3:27 pm    Post subject:
Reply with quote

Gaurav,
Glad to know that it helped you... icon_razz.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Convert current to hex value gopurs DFSORT/ICETOOL 4 Wed Feb 15, 2017 5:40 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us