Hello Edgard,
Probably, INSERT... ON EXISTING UPDATE would not solve it.
I think that the MERGE statement will meet your purpose.
The MERGE statement can describe different action in UPDATE and INSERT.
Please see the following online document.
"MERGE statement"
(ver.12)
http://dcx.sap.com/index.html#1201/en/dbreference/merge-statement.html
(ver.16)
http://dcx.sap.com/index.html#sa160/en/dbreference/merge-statement.html
(ver.17)
http://dcx.sap.com/index.html#sqla170/en/html/8171ce016ce21014b630c0acb78fa8a8.html
(Example)
------------------------------------------------------------------------------------------------- -- INITIAL INVENTORY ------------------------------------------------------------------------------------------------- MERGE INTO InventoryMovement USING (SELECT ItemId,InventoryDate,Quantity FROM InventoryCount WHERE WarehouseId = @WarehouseId AND InventoryDate = @InitialDate) as InvCnt ON InventoryMovement.PlantId = @PlantId WHEN MATCHED THEN UPDATE SET InitialInventoryQty = InitialInventoryQty + InvCnt.Quantity WHEN NOT MATCHED THEN INSERT( [column-lists] ) VALUES ( [values] ); |
* The design of table and columns of the example will be wrong.
* Because I don't know your database schema and detailed goal.
Regards,
Koichi