I have a question, it may seems to be easy but i am having hard time to figure it out, any help is greatly appreciated.
so the problem is, once the delivery of product with full release is finished, i want it to merge or replace the existing row with the same Product_Section and Product_Name,
| Id | Product_Name | Product_Section | Product_Release_Status |Product_Delivery_Status|
--------------------------------------------------------------------------------------------------
| 1 | Paper | 101 | Full | Ongoing |
| 2 | Paper | 101 | Partial | Finished |
if i insert the values(1, 'Paper', 101, 'Full', 'Finished') again for update using the following procedure below,
and this is what i get.
| Id | Product_Name | Product_Section | Product_Release_Status |Product_Delivery_Status|
--------------------------------------------------------------------------------------------------
| 1 | Paper | 101 | Full | Finished |
| 2 | Paper | 101 | Partial | Finished |
Whereas the Expected Output should be:
| Id | Product_Name | Product_Section | Product_Release_Status |Product_Delivery_Status|
--------------------------------------------------------------------------------------------------
| 2 | Paper | 101 | Full | Finished |
i hope you'll get what i mean. im probably new to database programming, i hope someone can help me. Thank you.
What I have tried:
PROCEDURE `MY_Products_InsertUpdateByDelivery`(IN _myId INT, _myProductName VARCHAR(50), _myProductSection INT, _myProductReleaseStatus VARCHAR(50), _myProductDeliveryStatus VARCHAR(50))
BEGIN
IF EXISTS(SELECT Product_Section from tbl_products Where Product_Name LIKE _myProductName AND
Product_Release_Status LIKE 'Partial') THEN
UPDATE
tbl_products
SET
Product_Release_Status = _myProductReleaseStatus,
Product_Delivery_Status = _myProductDeliveryStatus
WHERE
Product_Section = _myProductSection
AND
Product_Name = _myProductName;
DELETE FROM
tbl_products
WHERE
Id = _myId;
ELSE
UPDATE
tbl_products
SET
Product_Release_Status = _myProductReleaseStatus,
Product_Delivery_Status = _myProductDeliveryStatus
WHERE
Product_Section = _myProductSection
AND
Product_Name = _myProductName;
END IF;
END