Is this possible to store the decimal type value in number column. 1/12 will be 0.083 and wants to store that in that column.
create table test(number1 int,number2 int,number float) insert into test values(1,12,CAST(CAST(1/12 AS decimal(9,2)) AS float))
i have tried cast function but it not worked
Advertisement
Answer
Of course it. The problem you are having is that 1 / 12
is 0
, because SQL Server does integer division.
Instead use 1.0 / 12
.
Here is a db<>fiddle illustrating the difference.