TSQL Divide problem, Decimal not shows. “/”

Today I try to create a round up function on TSQL, which is use to override the normal Round function that provided by MSSQL server.
When I try to do 1/10, it returns 0 rather than 0.1
It is so strange
E.G.
DECLARE @i AS FLOAT
SET @i=1

SELECT @i/10

I tried it several time, and asked my friend how to do it as well.
Unfortunately we have no idea as well.

Finally, I just remember i had similar problem before, I solved it by putting a decimal number onto the value and it just work fine again.

E.g.
DECLARE @i AS FLOAT
SET @i=1.0

SELECT @i/10

Then I went to MSDN to read up about it, it said:

Result Type
<

If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated.>>

For more information please visit the URL below.
http://msdn.microsoft.com/en-us/library/ms175009.aspx11

Hope you find it useful.

Leave a Reply