
Hello everybody,
I'm currently writing a flow that needs to read an Excel file (Raw log data) into a SQL database.
For this I have constructed the following flow (In dutch):
(1. Open Excel
2. Find first free row
3. Read all Excel rows up to first free row
4. Connect SQL database
5. For reach row in Excel execute Stored Procedure 'SP_Uitvoer'
6. Close SQL connection
7. Close Excel)
This flow will work the first time, when there is not data in the SQL database yet. The problem is that when I execute the flow again, the error 'can not insert duplicate primary key' comes up. This makes sense, because currently I'm telling Power Automate to insert all values from the log file again.
What I want to do but don't seem to be able to figure out, is to only add in the new rows into the database.
If anyone could enlighten me on how to do this, that would be marvelous! 🙂
For good measure, the Stored Procedure looks like this:
I think you need to modify your query with some IF NOT EXISTS stuff.
Check it out: SQL Server Insert if not exists - Stack Overflow