Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    19
    Provided Answers: 1

    Unanswered: how to convert a decimal(8,4) on SQL to a numeric(8,4) on DB2?

    I have a value (in SQL SERVER) that I am trying to insert into DB2.

    Declare @Measure float

    @Measure = SELECT -48.51

    INSERT OPENQUERY(AS400DB2, 'SELECT Measure FROM SomeTable')
    VALUES (Measure)

    I tried char(8) and it looks like this on sql server -4851 but in DB2 the field is Numeric(8,4) is -48.51 but if I send at 9999.9999 - the char(8) in SQL Server fails with Arithmetic overflow error converting numeric to data type varchar.


    select cast(9999.9999 as char(8))


    Please help. As I need answer asap. Thanks.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    The problem lies in your code, not in DB2. When I run:
    Code:
    select cast(9999.9999 as char(8))
    in Microsoft SQL 2012, it returns:
    Code:
    Msg 8115, Level 16, State 5, Line 1
    Arithmetic overflow error converting numeric to data type varchar.
    Your SQL statement in DB2 or Transact-SQL ought to be:
    Code:
    select cast(9999.9999 as char(9))
    This runs fine in both DB2 and Microsoft SQL Server 2012.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Sep 2005
    Posts
    19
    Provided Answers: 1

    DB2 can only handle numeric(8,4) it can't handle char(9)

    IN DB 2 the Measure field is Numeric(8,4) - setting char(9) would fail. How do I convert my data on sql end so the insert WON'T fail on DB2 end?

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I don't have a DB2 server that I can test this with today, but you ought to be able to use:
    Code:
    Declare @Measure NUMERIC (8, 4)
    
    SET @Measure = -48.51
    
    INSERT OPENQUERY(AS400DB2, 'SELECT Measure FROM SomeTable')
       VALUES (@Measure)
    
    SET @Measure = 9999.999
    
    INSERT OPENQUERY(AS400DB2, 'SELECT Measure FROM SomeTable')
       VALUES (@Measure)
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

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