Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2006
    Posts
    13

    Unanswered: 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?

  2. #2
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •