If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > CHAR --> DECIMAL --> CHAR conversion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-21-04, 01:21
Jake K Jake K is offline
Registered User
 
Join Date: Feb 2004
Posts: 107
CHAR --> DECIMAL --> CHAR conversion

I want to convert a CHAR value to DECIMAL and then add some numeric value to it and then convert it back to CHAR.

While converting the decimal value into CHAR, it appends 0's to the left side of the value to make the converted CHAR size to 18 characters. How can i avoid this??? I don't want those 0's..

see this test code:
db2 select char(decimal('0')+1) from sysibm.sysdummy1

1
------------------
0000000000000001.

1 record(s) selected.

Thanks in advance & hope to hear your feedback.

Jake
Reply With Quote
  #2 (permalink)  
Old 09-21-04, 10:05
Metatron Metatron is offline
Registered User
 
Join Date: Feb 2004
Posts: 21
Quote:
Originally Posted by Jake K
I want to convert a CHAR value to DECIMAL and then add some numeric value to it and then convert it back to CHAR.

While converting the decimal value into CHAR, it appends 0's to the left side of the value to make the converted CHAR size to 18 characters. How can i avoid this??? I don't want those 0's..

see this test code:
db2 select char(decimal('0')+1) from sysibm.sysdummy1

1
------------------
0000000000000001.

1 record(s) selected.

Thanks in advance & hope to hear your feedback.

Jake
HI,
you can use substr.
Reply With Quote
  #3 (permalink)  
Old 09-21-04, 10:13
urquel urquel is offline
Registered User
 
Join Date: Aug 2004
Posts: 330
Use the precision-integer and scale-integer options of the DECIMAL function to specifiy the precision and scale of the result. (You will still get zeroes, just less of them) OR You could use LTRIM to remove zeroes from the resulting string, but if the result is 0000000000000000 you get nothing.
Reply With Quote
  #4 (permalink)  
Old 09-29-04, 09:05
rdmurthi rdmurthi is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
Try
select cast(char(cast(decimal(c1)+1 as decimal(1))) as char) from sysibm.sysdummy1

Dakshinamurthi
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On