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 > Problems casting an integer to a varchar

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-17-07, 14:28
Yukke Yukke is offline
Registered User
 
Join Date: Jul 2006
Posts: 13
Problems casting an integer to a varchar

I have a column that contains integers values for the number of documents.

select cast(cast(JOB_TOTAL_DOCS as char) as varchar(254)) docs...

When I try to cast the integer as char then to varchar.. the results would be concatenated into 1 character.

For example: if the original integer was 5691, after the cast the resulting varchar would be '5'. 753->'7', etc.

What am I doing wrong?
Reply With Quote
  #2 (permalink)  
Old 10-17-07, 14:43
nidm nidm is offline
Registered User
 
Join Date: May 2003
Posts: 113
cast(JOB_TOTAL_DOCS as char) means:
cast(JOB_TOTAL_DOCS as char(1))

You need to specify the length yourself.

Quote:
Originally Posted by Yukke
I have a column that contains integers values for the number of documents.

select cast(cast(JOB_TOTAL_DOCS as char) as varchar(254)) docs...

When I try to cast the integer as char then to varchar.. the results would be concatenated into 1 character.

For example: if the original integer was 5691, after the cast the resulting varchar would be '5'. 753->'7', etc.

What am I doing wrong?
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