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) +
CAST(ISNULL(d.Size2,0) AS DECIMAL)
) / 1024 /1024 -- don't use 1024 * 2
FROM T.dbo.doc d
UNION
SELECT
id.edoc_id,
id.media_id ,
SIZE_MB= CAST(ISNULL(id.Size,0) AS DECIMAL ) / 1024 / 1024
FROM T.dbo.importdoc id
) AS X
group by media_id
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) +
CAST(ISNULL(d.Size2,0) AS DECIMAL)
) / 1024 /1024 -- don't use 1024 * 2
FROM T.dbo.doc d
UNION
SELECT
id.edoc_id,
id.media_id ,
SIZE_MB= CAST(ISNULL(id.Size,0) AS DECIMAL ) / 1024 / 1024
FROM T.dbo.importdoc id
) AS X
group by media_id
Comments
Post a Comment