adambom
July 31st, 2008, 07:55 AM
Hello folks,
I'm trying to do simple division in T-SQL, but the division operator (/) always returns an integer. I need it to return at least a couple decimal places. I've tried multiple things such as:
RETURN @Var1/@Var2
RETURN CAST(@Var1 AS FLOAT)/CAST(@Var2 AS FLOAT)
RETURN CAST(CAST(@Var1 AS FLOAT)/CAST(@Var2 AS FLOAT) AS FLOAT)
RETURN CAST(@Var1 + '.0' AS FLOAT)/CAST(@Var2 + '.0' AS FLOAT)
Even 1.0/2.0 will return 0!
I have no idea why SQL Server is being this difficult. Can anybody offer help?
I'm trying to do simple division in T-SQL, but the division operator (/) always returns an integer. I need it to return at least a couple decimal places. I've tried multiple things such as:
RETURN @Var1/@Var2
RETURN CAST(@Var1 AS FLOAT)/CAST(@Var2 AS FLOAT)
RETURN CAST(CAST(@Var1 AS FLOAT)/CAST(@Var2 AS FLOAT) AS FLOAT)
RETURN CAST(@Var1 + '.0' AS FLOAT)/CAST(@Var2 + '.0' AS FLOAT)
Even 1.0/2.0 will return 0!
I have no idea why SQL Server is being this difficult. Can anybody offer help?