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 / MS SQL Result Sets to ...
Power Automate
Unanswered

MS SQL Result Sets to Excel Online with Separate Sheets

(0) ShareShare
ReportReport
Posted on by

I have created a Stored Procedure in MS SQL that returns a different result set based on the value of the parameter passed into it. I am planning on putting all the results into an Excel file with separate sheets that is named as the parameter passed into the procedure.

 

I've used Excel Online For Business as a connection then I created a blank spreadsheet in the Blob then I am planning it on saving into the User's One Drive after the flow is finished. Here's what I got so far

 

Excel Extract 1.jpgExcel Extract 2.jpg

 

But It's not working. I'm not sure what steps am I missing. (I just added the Add a row into a table action but not sure what parameters to put)

Is there a way also to create an Excel file without having it made initially like I did? Because if this runs successfully there's an extra sheet named Sheet1 upon opening the file. 

 

Really appreciate if someone can point me into right direction. Thank you in advance.

Categories:
I have the same question (0)
  • Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at

    Hi @RazenC 

     

    To add row to table, You have to pass the data which needs to be added as row to table. See below. I am assuming that in your flow, Create CSV Table output is used to populate rows to table

    Nived_Nambiar_0-1717418524233.png

     

    Nived_Nambiar_1-1717418558804.png

     

    Now coming to add details to excel from csv table action, Here in my csv table created as part of action, I have 2 columns - A and B as shown below

    Nived_Nambiar_2-1717418616451.png

     

    (Ignore values and columns - added for understanding purposes)

     

    Now same thing i have added in json format when adding row to table

    {
    "A": "@{items('Apply_to_each')?['A']}",
    "B": "@{items('Apply_to_each')?['B']}"
    }

     

    Similarly u can add the details as well with little changes.

     

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel
    Blog: Nived Nambiar's Blogs

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

     

  • Verified answer
    RazenC Profile Picture
    on at

    I managed to complete this flow. Hoping if someone found this, hoping to provide you some information.

    Let's say you have a SQL Stored Procedure that accepts a parameter. The result of the procedure is based on the parameter being passed.


    For example usp_get_Customers 'Company 1' or it can be 'Company 2' etc.
    They return same number and name of columns but different records.

     

    I've created a new Excel file with 3 different sheets and saved it in my BLOB or One Drive or any location you will point the flow
    Make sure you named the sheets according to what you want.


    Now in the flow, to start this.

    1. Create an array of string that contains the names similar to the sheets in your Excel file.
    2. Create an array of string parameter values you need to pass in the Stored Procedure
    3. Create a variable of Integer and set it to 0, this acts as Index of looping for the variable in Step 2.
    4. Create a variable of blank String this should be the place holder of value being looped in Step 2.
    5. Create a variable of boolean, I named it FileIsLocked and set it to true. (This is for the creation of Excel file in the User's One Drive)

     

    01 Power Automate.jpg

     

    Next thing I did, I need to copy the file from BLOB to the User's One Drive.

     

    6. Point the BLOB to the location of the file
    7. Create Do Until with condition that points to our variable in step 5.
    Note: We need to do this because sometimes it returns an error that the file is still locked. (Look in the other articles for details)

     

    02 Power Automate.jpg

     

    8. Inside the DO Until add an action Create File from One Drive. Just fill up the File name you want then get the dynamic value generated from the body of the BLOB
    9. Still inside the Do Until Update the FileIslocked value. Make sure this action is set to run whether it is Successful or Has failed.

     

     

    03 Power Automate.jpg

     

    10. After the DO until create an Apply to each and loop through the variable we created from step 1
    11. Inside the loop, set the value of variable from step 4 into this: variables('TableNames')[variables('TableIndex')]
    13. Inside the loop, Add an Execute Stored Procedure action then add the parameter current item from step 10 which are the name of the Sheets

    04 Power Automate.jpg

     

    14. Add an action Create table from Excel. Take note that you need to use the Id from One Drive in the File properties.

     

     

    05 Power Automate.jpg

     

    15. Next is just increment the variable from step 3
    16. Still inside the Apply to Each loop, add an If Condition that check if there are records being returned from stored procedure:
    empty(body('Execute_stored_procedure_(V2)')?['resultsets']?['Table1'])

     

    06 Power Automate.jpg

     

    17. When the condition is True, Add Apply to Each to the body of the result set:
    body('Execute_stored_procedure_(V2)')?['resultsets']?['Table1']

    18. Inside the Apply to Each, Add an action Add a row into a table

     

    07 Power Automate.jpg

     

    File property point to the Id from Step 8
    Table property points to the Title from Step 14
    Row property make sure follow the format in the screenshot. The value for each is: item('Loop_DB_Row')?['YourColumnName']

     

     

    Hope this helps!

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 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard