Question: I want to get the result of this query but I'm getting the following error

> 
> Arithmetic overflow error converting expression to data type int
> 
> 
> 

```
SELECT d.name,
ROUND(SUM(mf.size) * 8 / 1024, 0) Size_MBs
FROM sys.master_files mf
INNER JOIN sys.databases d ON d.database_id = mf.database_id
WHERE d.database_id > 4 
GROUP BY d.name
ORDER BY d.name

```

Answer: 
Try converting to bigint:

```
SELECT d.name,
ROUND(SUM(convert(bigint,mf.size)) * 8 / 1024, 0) Size_MBs
FROM sys.master_files mf
INNER JOIN sys.databases d ON d.database_id = mf.database_id
WHERE d.database_id > 4 
GROUP BY d.name
ORDER BY d.name

```
It's breaking because when you sum mf.size, it exceeds the max number datatype int can hold which is 2,147,483,647. To fix it, just cast mf.size and alternatively \*8/1024 can be written as /128.0 like so:

```
SELECT d.name,
ROUND(SUM(CAST(mf.size AS bigint))/128.0, 0) Size_MBs
FROM sys.master_files mf
INNER JOIN sys.databases d ON d.database_id = mf.database_id
WHERE d.database_id > 4 
GROUP BY d.name
ORDER BY d.name

```