can anyone explain to me why this query returns 0.000?
SELECT CAST(20/1024 AS NUMERIC(10,3))
I am just trying to do a simple conversion of MB to GB
You are doing an integer division first and then convert the result. The integer division results in 0. Converting 0 to
MS SQL Server 2008 Schema Setup:
To get a non-integer-division you need to convert at least on of the two numbers involved to something other than an integer. In the case of number literals you can just add a
In the case of variables or columns you need to convert one of them using
Actually I fixed it already, its because I had to cast each integer not the whole thing. So this worked:
You're using the divide operator to do a integer division.
To get a result with a decimal part, you should first convert one of the operands to a different data type – either
For example (SQL Fiddle):