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 / Insert/ Update SQL Server
Power Automate
Unanswered

Insert/ Update SQL Server

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

 

My goal is to have users update an excel table and have the data be pushed to a SQL Server table. 

 

I'm trying to create a conditional Insert/Update statement in Power Automate based on Row ID. I have two tables right now with the same columns. 

 

1) Excel Table

2) SQL Server Table

 

I'd like to INSERT a row into the SQl Server Table from the Excel Table IF the ID in Excel Table is NOT in SQL Server table. Otherwise, I'd like to UPDATE the SQL Server Table with the info from the Excel table. 

 

I can get the Update and Insert statements to work separately, but can't get the condition yes/no action to work. 

 

Any help?

 

Categories:
I have the same question (0)
  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    Try this:

    Get items 
    Condition -> ID Excel = ID SQL 
    If yes, update item
    If no, create item + end flow

     

    If you dont have that end flow, it will create more items like that

    If that does not work. In the condition you can see if created = utcNow(). If yes, you create a new item in sql (because that item is also new in excel)
    If no, you update that item

  • eric-cheng Profile Picture
    5,171 on at

    Hi @greenguy2020 ,

     

    I posted this in another post but it should hopefully assist you.

     

    Option 1 - Execute SQL Query  

     

    Use Execute SQL Query to execute a Select query to return a count e.g. select count(ID) as count where excel.id = sql.id

     

    Add a Compose action underneath and go to expressions and paste this in (you may need to tweak Parse_JSON depending on the name of the action in the previous step).  What this does is to return the first JSON object in the index and count field.

     

    body('Parse_JSON')?['ResultSets']?['Table1'][0]['count']
     
    ericcheng_3-1626156294637.png

     

    When you run it, it should return the count of rows which you can then use in your condition.  If a count is greater than 0, a row exists and you can run the Update statement, else, run the Insert statement

     

    ericcheng_4-1626156429369.png

     

    Option 2 - Get Items  

     

    You could also try the Get rows (v2) action with a filter.  You can then get the length of the value to get the row count.

     

    length(body('Get_rows_(V2)')?['value'])
     
    ericcheng_0-1626155573095.png

     

    Again, you can then use in your condition.  If a count is greater than 0, a row exists and you can run the Update statement, else, run the Insert statement
     
    --------------------------------------------------------------------------
    If I have answered your question, please mark my post as a solution
    If you have found my response helpful, please give it a thumbs up

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 552

#2
Valantis Profile Picture

Valantis 388

#3
11manish Profile Picture

11manish 375

Last 30 days Overall leaderboard