Friday, December 26, 2008

division in SQL results in 0 Zero

division in SQL results in 0 Zero

What is happening is that you divide an integer value by another integer value => result is an integer. You can read up on this in BOL when you search for data type precedences (I think so).

A simple way to prevent this is to use: (multiply by 1.0 to become a float)

set @a =cast(56278 as float)
set @b= cast(79089 as float)
set @c = @a * 1.0 / @b

No comments: