Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - General Discussion
Unanswered

Assign Execute a SQL query (v2) to a variable

Like (0) ShareShare
ReportReport
Posted on 6 Oct 2023 17:51:36 by 84

Is there any way that I can assign my SQL SELECT statement result to a variable so that I can use it in further steps?

In the same way we declare variables in SQL and assign values to it.

  • Amirhz Profile Picture
    84 on 06 Oct 2023 at 19:25:32
    Re: Assign Execute a SQL query (v2) to a variable

    What can be the reason that step does not show up on the list at all!?

     

    AmirZolf_0-1696620312407.png

     

  • Michael E. Gernaey Profile Picture
    41,703 Super User 2025 Season 1 on 06 Oct 2023 at 19:17:36
    Re: Assign Execute a SQL query (v2) to a variable

    @AmirZolf  Can you scroll up and down in the dynamic window and see if its there. I only said click that one as I didnt see you had 2.

     

  • Amirhz Profile Picture
    84 on 06 Oct 2023 at 19:10:13
    Re: Assign Execute a SQL query (v2) to a variable

    Well, that is my problem. The body for that query does not populate.

    It is for the other one.

    AmirZolf_0-1696619389283.png

     

     

     

     

  • Michael E. Gernaey Profile Picture
    41,703 Super User 2025 Season 1 on 06 Oct 2023 at 19:00:02
    Re: Assign Execute a SQL query (v2) to a variable

    Hi @AmirZolf 

     

    body has what you need (its the results) If you click on body and add it to the compose. Then hover your mouse over the added property (dont click it) you wil see something like

    body('Execute_a_SQL_query_(V2)') 

     

    then you access your data (and I have no idea what yours looks like) via that.

    Essentially its a JSON Array. Which means you normally access it with an Apply to each, where you would put the body, in the Input.

     

    That would loop through your results.

    As it loops you would have access to the columns and their values based on the iteration of the loop as it goes row to row.

     

    I hope that makes sense.


    If I have answered your question, it would be helpful if you Mark my response as an Answer/Resolved and maybe even a thumbs up.


    Cheers
    If you like my answer, please Mark it as Resolved, and give it a thumbs up, so it can help others
    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

  • Amirhz Profile Picture
    84 on 06 Oct 2023 at 18:54:38
    Re: Assign Execute a SQL query (v2) to a variable

    There are other Dynamic contents there, but not this one!

     

    AmirZolf_0-1696618426124.png

     

  • Michael E. Gernaey Profile Picture
    41,703 Super User 2025 Season 1 on 06 Oct 2023 at 18:29:04
    Re: Assign Execute a SQL query (v2) to a variable

    @AmirZolf 

     

    You dont need too. Any action that you perform, the output is available to the rest of the flow. You just need to know what dynamic property to access.

     

    The output of a SQL Query would be an Outputs or Body which is going to be an Array of your Results

     

    If you show your flow, and if you add a Compose right after your Query Action. Then just click in the box, let the Dynamic Properties windows popup. Scroll to the section that is for the Output of your SQL Action and you will see. Please feel free to share the image if you are having issues finding it.

     

    Please mark this as Resolved and maybe also a Thumbs Ups.

     


    Cheers
    If you like my answer, please Mark it as Resolved, and give it a thumbs up, so it can help others
    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,771 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard