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 / Add new column to Data...
Power Automate
Answered

Add new column to Datatable via sql statement

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello all,

I currently need help with how to add a new column to my datatable. I have read my data through a SQL statement and I want to add a new column with a query "ALTER TABLE %QueryResult% ADD UserID VARCHAR(10)" but I kept getting the error: Error in SQL statement Syntax error in ALTER TABLE statement.

Is this possible to achieve?

Emmy123_0-1637162035567.png

Any help will be appreciated!

I have the same question (0)
  • VJR Profile Picture
    7,635 on at

    Hi @Anonymous ,

     

    'QueryResult' is a Datatable variable of PAD and the SQL command won't work on that variable. 

     

    • Instead add a column to your Excel
    • And then execute Line nos 10 and 11 from your screenshot.

     

    Here is the logic:

    - If the Excel looks like this

     

    VJR_2-1637204594258.png

     

     

    - Find the first free column 

     

    VJR_0-1637204464143.png

     

    - Then add a new column 

     

    VJR_1-1637204540738.png

     

    - After executing the flow it will add a new column

     

    VJR_4-1637204818017.png

     

     

     

    - Now Run your line nos. 10 and 11

    The resulting datatable 'QueryResult' should have the new column.

  • VJR Profile Picture
    7,635 on at

    Another option:

    Line no 12.

    Since Sheet2$ is now your database table, try adding column to that instead of adding to QueryResult.

     

    ALTER TABLE [Sheet2$] ADD column_name datatype

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi VJR,

    Many thanks for your reply. I have tried using ALTER TABLE [Sheet2$] ADD column_name datatype yesterday but that also did not work. The workaround that I employed earlier was to create a new empty datatable with all the columns that I needed using  Set variable, and then read the old datatable into it through a For each loop. This does not look like an efficient solution to me especially when the table has a lot of rows. This was why I thought it would be easier to achieve with an SQL query but it is unfortunate to learn that this is not possible. 
    I hope datatable activities in PDA will be developed soon so that we can have all the possibilities to easily carry out some of these actions that are available in other RPA solutions.

  • VJR Profile Picture
    7,635 on at

    Hi @Anonymous 

     

    Did you take a look at the approach in the first post after your original question which does not involve looping?

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi VJR,

    Yes, I considered this option but it is not a suitable solution for me because I need to add 3 columns to this table and I need to update these columns in another workflow. Following this approach would mean that I have to implement write to Excel 3 times and then read the final excel sheet before I can use it in another workflow.

  • yoko2020 Profile Picture
    495 on at

    @Anonymous 

     

    1. Use excel template which contain all of the column.
    2. You can write directly variable %QueryResult% to that excel template and save excel as new file.

     

  • Verified answer
    VJR Profile Picture
    7,635 on at

    @Anonymous 

    Okay 🙂, using 3 statements are far much better than looping a datatable.

     

    If you dont need anything further you can close this thread.

    And if you need to suggest any datatable related activities to MSFT then you can do it here.

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 July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 266 Super User 2026 Season 2

#2
trice602 Profile Picture

trice602 160 Super User 2026 Season 2

#3
11manish Profile Picture

11manish 134 Super User 2026 Season 2

Last 30 days Overall leaderboard