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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Execute SQL Statement:...
Power Automate
Unanswered

Execute SQL Statement: variable from two different server into a sql query

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello everyone, I am facing a problem.

 

I have two sql connections (two different server). I execute one query in the first connection and save the data in a variable (%QueryResult%). In the second connection I do another query but I want to put data from the first connection %QueryResult% into my sql query, but the result is always nothing.

Select
*
From
Tabel1
Where
List in (%QueryResult%)

 

QueryResult = Datatable :

 

Name111

Name112

Name113

Name114

 

When I do it directly in MS SQL Server Management Studio i would usually type in 

 

Select
*
From
Tabel1
Where
List in 

('Name111',

'Name112',

'Name113',

'Name114')



Do some have a solution?

I have the same question (0)
  • Gene_Liang Profile Picture
    2 on at

    Hi, I think the issue you faced was the conversion between variable types, can you click on the %QueryResult% in variable pane while the process was executed and post the screen capture so I can help you sort things out ?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hello @Anonymous 

     

    You have to convert from Datatable to List at first.

    Use action "Retrieve data table column into list" to do so.

     

    shindomo_1-1635576894505.png

     

    Then use the action "Join text" to convert the list into a comma-separated string. Since we need to enclose each value in quotation marks, we need to set the custom delimiter to ','.

     

    shindomo_0-1635578536643.png


    Finally, pass a comma-separated string to the IN operator of the WHERE clause of the SQL statement. Don't forget to enclose variable in quotation marks.

    SELECT * FROM [Employees]
    WHERE [LastName] IN ('%JoinedText%');

     

    shindomo_1-1635578610519.png

     

    Best Regards.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 262 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 167

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard