• SQL Kiwi (1/4/2012)


    As far as I recall, the issue with multiplying or dividing by one was a bug in type inference, which has since been fixed.

    Well, I'm on an XP platform so I can't test if it is fixed in Denali, but it certainly isn't fixed in SQL 2008 R2 with latest updates.

    Maybe someone could try this in Denali:

    use tempdb

    set nocount off

    go

    declare @t table (A decimal(38,5) primary key, B decimal(2,1))

    insert @t(A,B) values((1234567890.0*10000000000.0*10000000000*1000)+0.12345,1.0)

    select A,B from @t

    select A*B from @t

    and see if they get this result in the messages tab of ssms:-

    (1 row(s) affected)

    (1 row(s) affected)

    Msg 8115, Level 16, State 2, Line 4

    Arithmetic overflow error converting expression to data type numeric.

    which clearly shows multiplication by one generating overflow. And the similar overflow for division can be demonstrated by changing "*" in the last line of that code to "/".

    You are right that it's a type inference problem, of course - if you have types where the precision and scale (in the T-SQL sense; T-SQL makes awfully inaccurate use of both those terms, of course, so this is far from the normal sense) are part of the type definition and you also allow type inference to decide the type of a computed column in a table definition so that the definition doesn't have to specify that type you will have to have a mechanism for allowing a special type inference to decide precision and scale; that becomes a problem when you allow that same special mechanism to rule when the result of the computation is being assigned to a column or variable of known type, because overflow should be determined by whether the value resulting can be represented in that known type, not on whether some rather pointless kludge to avoid explicitly defining the type of a computed column when defining the table that contains it would implicitly produce a type that would allow the value to be represented.

    Tom