SQL query - number of archived items per archive
Hi,
Need an assistance with an SQL query that will bring the following result:
list of all archives, number of total items archived for archive, number of items archived per archive for 2014 only, and size of all items in the the archive.
I found different queries here, but I do not know SQL that good, so I was unable to join them :(
Thanks,
Sarah
This might work:
SELECT
EME.MbxDisplayName "Mailbox Name",
PTG.DisplayName "Provisioning Group",
COUNT(S.ItemSize) "No. Items Archived",
SUM(S.ItemSize)/1024 "Archived Item Size (MB)",
SUM(SP.OriginalSize)/1024/1024 "Original Item Size (MB)",
SUM(CASE when CAST(Year(ArchivedDate) as int) = 2014 then 1 else 0 end) as 'Num in 2014'
FROM
dbo.Saveset S,
dbo.SavesetProperty SP,
dbo.ArchivePoint AP,
EnterpriseVaultDirectory.dbo.ExchangeMailboxEntry EME,
EnterpriseVaultDirectory.dbo.PolicyTargetGroup PTG
WHERE
S.SavesetIdentity = SP.SavesetIdentity
AND S.ArchivePointIdentity = AP.ArchivePointIdentity
AND AP.ArchivePointID = EME.DefaultVaultId
AND EME.PolicyTargetGroupEntryId = PTG.PolicyTargetGroupEntryId
GROUP BY EME.MbxDisplayName, PTG.DisplayName
ORDER BY PTG.DisplayName, EME.MbxDisplayName