Converting from bytes to terabytes is very easy considering that terabyte = 1024*Gigabyte = 1024 * 1024 * Megabyte = 1024 * 1024 * 1024 KiloByte = 1024 * 1024 * 1024 * 1024 * Byte Query below gives number of documents in a media and the total size of the documents. See how you have used Alias in the query SELECT [MEDIA] = X.media_id, [TOTAL] = COUNT(*), [Size_KB] = SUM (Size_MB) FROM ( SELECT d.edoc_id, d.media_id , SIZE_MB = ( CAST(ISNULL(d.Size1,0) AS DECIMAL) + ...