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 > Cast INT to VARCHAR

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Jul 2004
Location: Ottawa, Canada
Posts: 58
Cast INT to VARCHAR

I read in db2 documentation that an INT can't be cast to a VARCHAR. Just thought I would post here to confirm...

EXAMPLE.
VALUES('a test' || CAST (123 AS VARCHAR(100)));

I want to concat the string to an integer, but to do that it needs to be converted to a varchar. Any sugestion?

Thanks
Reply With Quote
  #2 (permalink)  
Old
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,649
You can cast INT or BIGINT to CHAR ..
Otherwise, this looks OK

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Jul 2004
Location: Ottawa, Canada
Posts: 58
Casting to CHAR to VARCHAR worked, the only thing that had to be altered was that CHAR padded with spaces, so i had to RTRIM the white space after it was converted to VARCHAR

EXAMPLE:

VALUES('CHAR' || RTRIM(CAST(CAST(123 AS CHAR(100)) AS VARCHAR(100))) || 'END');


OUTPUT: CHAR123END
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