Hi everyone;
I am trying to update or inserting into a table depending of what is in the table. However, is gives me the error: Unknown column name' in 'field list'.
- Name is a column from the "Sold" table.
- I am trying to compare if that item is already in the table for the current month
I am trying to update or inserting into a table depending of what is in the table. However, is gives me the error: Unknown column name' in 'field list'.
- Name is a column from the "Sold" table.
- I am trying to compare if that item is already in the table for the current month
If it is update sold table and increase the quantity of those items by one
else insert a new row in the table.
Code:
SELECT *
FROM sold;
IF name = v_ItemName AND time=DATE_FORMAT(NOW(), '%m') THEN
UPDATE sold
SET number_sold=number_sold + 1
WHERE name =v_ItemName ;
ELSE
INSERT INTO sold
(name, itemprice, quantity, time)
VALUES
(v_ItemName , v_itemprice, 1, DATEFORMAT(NOW(),'%m');
END IF;