If you are talking about presentation of the result and use MS SQL Server 2012 or higher, you can use the function FORMAT
to determine the number of boxes after the comma, thus:
select format(1234.5678, '#.000')
The result will be 1234.568
(see that it was rounded).
And, to present without any decimal place:
select format(1234.5678, '#')
The result will be 1235
(also rounded).
Update: In previous versions, you can use the function ROUND
:
select round(1234.5678, 3)
select round(1234.5678, 0)
Results: 1234.568
and 1235
.
Or you can convert the value to DECIMAL
limiting the number of decimal places:
select cast(1234.5678 as decimal(10, 3))
select cast(1234.5678 as decimal(10, 0))
Results: also 1234.568
and 1235
.
At your command, simply apply the chosen method to each column resulting from the SELECT command. For example:
SELECT
rtrim(name)as name,
ROUND(((size)/128.0), 3) as'size in MB',
ROUND(((size)/128.0) -CAST(FILEPROPERTY(name,'SpaceUsed')AS int)/128.0, 3)
AS AvailableSpaceInMB,
ROUND(((((size)/128.0)
-CAST(FILEPROPERTY(name,'SpaceUsed') AS int)/128.0)
/((size)/128.0)) * 100, 0) as'% Available',
filename
FROM
sysfiles
Could you please give me an example for versions prior to 2012? Can you also format this query I left so that it is displayed in these conditions? Thanks.
– Jean Braz
@Jeanbraz I updated my reply with options for previous versions.
– Caffé