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 > String + Decimal Concatenate

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-17-09, 06:12
dinjo_jo dinjo_jo is offline
Registered User
 
Join Date: May 2008
Posts: 34
String + Decimal Concatenate

Query

Code:
select COLA || '|', - String
         COLB '|', - Decimal 
         COLC '|', - String
         COLD '|', - Decimal
         COLE - String
from TABLEA
Problem is since the decimal datatypes contain records which are numbers they gets converted to char as use char(colb)

Sample Output before conversion
Code:
ABC 48.0000 POP 49.75000 OOO
But when concatenate happens the number changes to like this

Sample Output after conversion
Code:
ABC|000048.0000000|POP|000000049.00000000|OOO
Should be
Code:
ABC|48.0000|POP|49.75000|OOO
Since the 000 are not consistent i can't use a replace function.
What i need is concatenate the record with Pipe Separated but the decimal values should be intact.

Last edited by dinjo_jo; 12-17-09 at 06:15.
Reply With Quote
  #2 (permalink)  
Old 12-17-09, 06:27
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
change the data type and strip it. For instance strip(char(colb),l,'0')

Dave
Reply With Quote
  #3 (permalink)  
Old 12-17-09, 06:38
dinjo_jo dinjo_jo is offline
Registered User
 
Join Date: May 2008
Posts: 34
would it remove the correct 000 which are after 48.0000
Reply With Quote
  #4 (permalink)  
Old 12-17-09, 13:19
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
you can, also, use B instead of L, this would remove leading and trailing. Another way of doing this if say you want to retain 2 places after the decimal point would be to use a substr along with the strip of leading 0's.

Dave
Reply With Quote
  #5 (permalink)  
Old 12-17-09, 13:58
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
if say you want to retain 2 places after the decimal point
STRIP( CHAR( DEC( colb , xx , 2 ) ) , L , '0' )
Reply With Quote
  #6 (permalink)  
Old 12-17-09, 14:11
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Exclamation EZer

Simply:

Code:
select COLA || '|' || varchar(COLB)  || '|' ||
       COLC || '|' || varchar(COLD)  || '|' || COLE
    from TABLEA
Lenny
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