Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2003
    Posts
    5

    Red face Unanswered: Cast problem : SYSIBM.INTERGER can't be cast into SYSIBM.VARCHAR

    Hi All,
    I'm migrating a database from SQL Server 2k to UDB DB2 for windows (version 8.1). I have a big problem on how to convert an integer to varchar.
    ......
    UPDATE TCRD
    SET NDOSS = '1/' ||
    CAST(MS7.substring(CAST(year(CURRENT TIMESTAMP) AS VARCHAR(30)), 3, 2) AS VARCHAR(30))
    .......

    This code produce an error on DB2 :
    SQL0461N and SQLSTATE=42846
    An SYSIBM.INTERGER can't be cast into SYSIBM.VARCHAR

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    If you look in chapter 3 of the SQL reference manual (V7.x), there is a chart on what is valid for casting between data types. It clearly states that you cannot directly cast from INTEGER to VARCHAR. But if you look at it, you can cast from INTEGER to CHAR to VARCHAR.

    so you can do:

    cast(cast(myinteger) as char) as varchar)

    HTH

    Andy

  3. #3
    Join Date
    Apr 2003
    Posts
    5
    Originally posted by ARWinner
    If you look in chapter 3 of the SQL reference manual (V7.x), there is a chart on what is valid for casting between data types. It clearly states that you cannot directly cast from INTEGER to VARCHAR. But if you look at it, you can cast from INTEGER to CHAR to VARCHAR.

    so you can do:

    cast(cast(myinteger) as char) as varchar)

    HTH

    Andy

    Very thanks Andy!!!! I'm trying this solution.

Posting Permissions

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