Help with SQL

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 3 years, 10 months ago.

  • Author
    Posts
  • #9145
    Profile photo of ratty67
    ratty67
    Participant

    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

  • #9222
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

You must be logged in to reply to this topic.