Help with SQL

Welcome Forums General PowerShell Q&A Help with SQL

This topic contains 1 reply, has 2 voices, and was last updated by

5 years, 5 months ago.

  • Author
  • #9145

    Points: 1
    Rank: Member

    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

    Points: 1,785
    Helping HandTeam Member
    Rank: Community Hero

    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.

The topic ‘Help with SQL’ is closed to new replies.