Divide in SQL Server

soclose picture soclose · Mar 1, 2011 · Viewed 34.8k times · Source

In SQL Server 2005 Express, the result is below

SELECT 100 / 15 --Result 6

But I wanna get approximate value 7 (like using calculator)

100 / 15 = 6.6666..

How to make it in SQL Server?

Answer

Aleksi Yrttiaho picture Aleksi Yrttiaho · Mar 1, 2011

You have to use decimal numbers e.g. 100 / 15.0. If you use integers the result is interpreted as an integer and truncated to the largest integer that is smaller than or equal to the result.