Author Posts

August 6, 2013 at 7:53 pm

I have an sql query as show below. I would like to know how I can loop through a list of users and run this query per user.

I have code connecting to a single db but have never done so using multiple dbs.

Any help greatly appreciated.

SELECT A.ArchiveName,
COUNT(S.IdTransaction) "Num. Items Archived",
SUM(S.ItemSize)/1024 "Archived Items Size (MB)",
SUM(SP.OriginalSize)/1024/1024 "Original Email Size (MB)"
FROM EVDirectory.dbo.Archive A,
EVDirectory.dbo.Root R,
EVVaultStore.dbo.ArchivePoint AP,
EVVaultStore.dbo.Saveset S,
EVVaultStore.dbo.SavesetProperty SP
WHERE S.SavesetIdentity = SP.SavesetIdentity
AND S.ArchivePointIdentity = AP.ArchivePointIdentity
AND AP.ArchivePointId = R.VaultEntryId
AND R.RootIdentity = A.RootIdentity
AND A.ArchiveName = 'username'
GROUP BY A.ArchiveName

August 8, 2013 at 6:45 am

The fact that the query is pulling from multiple databases doesn't matter. It's a single query, returning a single result set. If you already have code that can connect to a database, then that same code should work for this, provided all the back-end permissions are correct.