Results 1 to 3 of 3
  1. #1
    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

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

  3. #3
    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

Posting Permissions

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