Search code examples
sybasesap-iq

Aggregate function AVG and SUM is changing my data type size column in SybaseIQ


I m reciving a error in Sybase Iq because the Aggregation funtion (AVG and SUM) is changing the size of my column, and when I insert the values of my aggregation funtion column in the destination column ,the results are so big for the destination column.

example:

            Salary
          -----------    
            0,4565
            0,4555
            0,4399
             ..
             ..

In my procedure i need to write

        SUM(salary)/AVG(salary)

when I write it

       select  SUM(salary)/AVG(salary) as AVG_Salary
          from mytable
             group by salary

I recive that as result

                AVG_Salary
             ----------------
            0,425000000000000000000000000  
            0,455000000000000000000000000
            0,442132124300000000000000000
            1,545646464743879540386969949
              ... 
              ...

Why is that? and if a try to round it, it doesnt work either,

what can I do?

Thanks for your kinds Answers.

AS suggestion i try to do the

   cast(AVG_Salary) as decimal (12,9)  --the size of my destination column

it doesnt work either. I recive the error "Data type conversion is not possible"


Solution

  • as stander SybaseIQ with the aggregation function shows the full result, but decimal should be not a problem in your destination table. if you tried the convertor

        cast(AVG_Salary) as decimal (12,9)  
    

    and you are having the problem of "Data type conversion is not possible" its simply because your data is too big.

    I mean its possible to do that:

                AVG_Salary           cast(AVG_Salary) as decimal (12,9)     
            ------------------      ------------------------------------    
              1,6655040959559          1,665504095    --ok                  
              12,666664554543          12,666664554   --ok
              1123,8190832083          --Error  
    

    the problem comes from your aggregation function SUM, probably it makes the result so big, and in that case "Cast" doesnt work, because cast reduce(round) decimals but its not the way to reduce your number. thats why you are receiving the problem of the "Data type conversion" its not a decimal problem it is a problem that your number is too big.