web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Looping 18 servers - n...
Power Automate
Suggested Answer

Looping 18 servers - need to know how

(1) ShareShare
ReportReport
Posted on by 27
Hi.
 
I am trying to loop through 18 servers to get the data into one excel spreadsheet/tab. I do have a code for every single server that are the same yet in the where clause, the environmentid changes to specific code for each server. I cannot use the UNION ALL in code as not allowed per company's server admins :/
 
from [planintegration].[dbo].[processlogheader] (NOLOCK) where processlogtypeid like 'AutoQ%'
and createdate >= getdate()-30
and [environmentid] = 4 (the code is different in each server)
 
You can see 2 different open SQL connections here. 
 
I have the same question (0)
  • Suggested answer
    fatiu Profile Picture
    83 on at
    Hi @Hopeisgood

    Firstly, you can easily handle this by simply creating a variable with array of environment Ids and DB connection, see below.



    Then iterate through the array and run the query for each id by dynamically parsing the current item into the Db connection details and in the where clause, see below

     
     
     
    This will run through all your dbs dynamically without having to repeat codes.
     
  • Hopeisgood Profile Picture
    27 on at
     
    Thank you for your replies. However, I am very confused. The snapshots did not indicate where I need to log into 18 different servers....
     
    The database is the same for all servers. 
     
    Thank you,
    Holly
  • Suggested answer
    fatiu Profile Picture
    83 on at
     
    This is what I believe you're trying to achieve is you have 18 databases and you want to pull data from each DB

    So I suggested that you:

    Initialize a variable that contains array 18 dynamic item that you might need for each DB (Like the parameters you need to specify on the where clause of your SQL Query).
    Also, Initialize a table that holds all of your data (maybe an excel instance)

    You then iterate through each item,

    within each iteration:~
    You connect your DB
    Run your SQL Query (Data is returned)
    Write the data to your initialized data source
    Close the DB

    Do the same for each iteration

    Then you'll be left with a data table that holds all of the data and you can do whatever you intend with it.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard