Failed to add if condition to procedure in MySql
I have the following procedure, but I want to add a condition to skip the transaction if my_status (From table myshop) is equivalent to 4. I want to add an if condition to the following code and try it, but I can't. Since I am noob, I have been stuck with this problem for quite some time. I have searched google and tried but cannot get it right. Some samples or tips would be great! I would love to hear from you!
BEGIN
INSERT
INTO `donut`.`myshop`
SELECT
vs.id
, vs.script_id
, 0 as my_status
, NULL as time_limit
, NULL as time_limit2
, NULL as time_limit3
, NULL as items
FROM
bread.reserve_table rt
LEFT OUTER JOIN baker.view_shops vs
ON rt.id = vs.id
WHERE
rt.start_date = CURRENT_DATE()
AND vs.start_date <> rt.start_date
ON DUPLICATE KEY UPDATE
id = values(id)
, script_id = values(script_id)
, my_status = values(my_status)
, time_limit = values(time_limit)
, time_limit2 = values(time_limit2)
, time_limit3 = values(time_limit3)
, items = values(items);
UPDATE
baker.shops s
SET
start_date = (
SELECT
start_date AS DATE
FROM
bread.reserve_table
WHERE
s.id = id LIMIT 1
)
,end_date = (
SELECT
end_date AS DATE
FROM
bread.reserve_table
WHERE
s.id = id LIMIT 1
)
,random_id = 0
,random_flg = 0
WHERE
EXISTS (
SELECT
1
FROM
bread.reserve_table
WHERE
s.id = bread.reserve_table.id
AND
bread.reserve_table.start_date =CURRENT_DATE()
AND
bread.reserve_table.start_date <> s.start_date
);
END
+3
source to share
No one has answered this question yet
Check out similar questions: