Update a record based on 2 identifiers
Application Type
Reactive

I'm trying to create a balance table of customers' currencies

Each customer has 2 currencies with different amounts

e.g.

Customer A  |  USD | 100 

Customer A | HKD | 800 

Customer B  | USD | 100 

...


When there is a transaction (e.g. Customer A receives 50 USD), it creates a new record of balance instead of updating the existing one.

Customer A | USD | 50  (New record)

Customer A  | USD |100 

Customer A | HKD | 800 

Customer B  | USD | 100 

...


How can I update the record according to the customer and the currency to achieve the following outcome?

Customer A | USD | 150  (Update the existing record)

Customer A | HKD | 800 

Customer B  | USD |  100 

...


Many thanks!!!


2022-03-02 01_42_59-ExchangeTable.png

Hi Wong,


Try to execute this logic.



Regards,

Riyas

Solution

Hi Wong,

you need to query the database before inserting any new record. 

  • In that query you must verify if the combination User | Currency already exists.
  • Sum the existing value in the database with the new value and Update the table instead of creating a new record

Regards


Hi Wong,


Try to execute this logic.



Regards,

Riyas

Thank you @Muhammed Riyas and @José Gonçalves!!! It works!!!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.