I have two tables t1
and t2
.
t1
has this structure:
yearmonth
account
company
RCV_amount_t1
t2
has this structure:
yearmonth
account
company
billing amount
billing amount CM_1
billing amount CM_2
RCV_amount_t2
I want to join t2
to t1
using yearmonth
, account
, and company
. If they match, I want to update RCV_amount_t2
with the value in RCG_amount_t1
. Otherwise, I want to set RCV_amount_t2
to spaces.
In the same manner, I want to join t1
with t2
using yearmonth
, account
, and company
and set values accordingly.
Is it possible to achieve? If so, how do I go about it?
You'll want to use a
MERGE
.It allows you to join two tables and specify how to update the values if they match.
The general structure of a
MERGE
statement looks like: