In Microsoft SQL Server 2005, why do the following commands produce integer results?
SELECT cast(151/6 AS DECIMAL(9,2))
SELECT 151/6
In Microsoft SQL Server 2005, why do the following commands produce integer results?
SELECT cast(151/6 AS DECIMAL(9,2))
SELECT 151/6
The CAST statement is a bit verbose. You can use the following instead:
DECLARE @TO_FLOAT FLOAT = 1.0;
SELECT (1 * @TO_FLOAT) / 2;
Or use a different multiplier type like DECIMAL if you prefer.