using (select a.* from fact_market_item_sales a where a.order_id=rec.order_id and a.market_ID=rec.market_ID and a.Product_id=rec.Product_id and a.item_quantity=rec.item_quantity) s on (s.order_id=t.order_id and s.market_id=t.market_ID --and s.category_id=t.category_id --and s.sub_category_id=t.sub_category_id and s.product_id=t.Product_id and s.item_quantity=t.item_quantity) when not matched then INSERT (order_id, market_id,product_id, item_quantity) VALUES (s.order_id, s.market_id, s.product_id, s.item_quantity) when matched then --update set DISCOUNT_AMT=total_price*discount_pct/100; --TAXABLE_VALUE= total_price-(total_price*15/100), --IGST_VALUEs=(total_price-(total_price*15/100)) * 18/100, --TOTAL_AMT=TAXABLE_VALUE+IGST_VALUE;