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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm


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