/
is integer division in SQL Server.
It means, that for example
SELECT 4 / 5
will return 0.
But, if you write
SELECT 4 / 5.0
you'll get 0.8
5.0
is treated as decimal
type and all values in the expression are converted to decimal
and division is no longer integer.
So, you can use 1024.0
constant in the expression, and all the values in it will be converted to decimal
type and division will not be integer.
In the question you say that you want to show results with two decimal places, so you should not convert result to int
.
select
[MB]
,round([MB]/(1024.0*1024.0), 2) AS TB
from df
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…