cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

How to avoid duplicate insertion into sql server while using Patch Statement?

Hello, 

I'm using Patch statement to Insert rows into two sql server tables. One table1, I'm able to insert userInfo and it generates unique ID. Then, I'm collecting the generated unique ID's(PK) into a collection with user information. After that, I'm using the ForAll formula to insert rows into table2 but the system is inserting duplicate rows in table2. Does anyone know how to avoid this?? Here is my formula. I'm not sure where I'm doing wrong.

 

ForAll(GetIDs,(Patch(
'[dbo].[table1]',Defaults('[dbo].[table1]'),
{
ID: Value(TransID),

Col2: "abc"

})

)

 

Thanks in advance. 

2 REPLIES 2
Highlighted
Community Support
Community Support

Re: How to avoid duplicate insertion into sql server while using Patch Statement?

Hi @Kitz ,

 

Can you share the Expression of creating collection?

I have made a test , and have no error with your formula.

Could you please check your collection to see if there are duplicate rows?

 

Best regard,

Sik

Highlighted
Helper I
Helper I

Re: How to avoid duplicate insertion into sql server while using Patch Statement?

Hi @v-siky-msft ,

The UserInfo Collection formula is: ForAll(ShoppingCart, Collect(Collection1, Patch('[dbo].[UserInfo]'),Defaults(('[dbo].[UserInfo]'), {Gender: GDropDown.Selected.Text, Date: UserDate.Selected.Date}))). This formula creates a unique ID in dbo.UserInfo table. 

I'm grabing this formula and storing it in Collection1. 

In the next step, I'd like to Patch items(Items of Shopping Cart) in dbo.Transactions table by using the ID generated from Table1. 

The formula I'm using here is :

ForAll(Collection1, Patch('[dbo].[Transactions]'), Defaults('[dbo].[Transactions']), {TID: Value(TID), ItemID: Gallery1.Selected.Label1.Text, ItemDesc: Gallery1.Selected.Desc.Text})))

 

I was able to insert rows in Transactions table in TID Column but other columns of second row are creating duplicates from first row. 

Hope this helps!!

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,055)