Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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 HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
This topic is locked: you cannot edit posts or make replies. Selecting two copybooks of different ... Vignesh Sid COBOL Programming 8 Tue Sep 05, 2017 7:28 pm
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us