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
mysql


source to share


No one has answered this question yet

Check out similar questions:

2568
Should I be using the datetime or timestamp datatype in MySQL?
1762
How to import SQL file using command line in MySQL?
1290
How do I get a list of user accounts using the command line in MySQL?
1112
What MySQL data type is used to store boolean values
1105
How to reset AUTO_INCREMENT in MySQL?
1086
How to connect to MySQL database in Python?
1069
Can multiple MySQL rows be concatenated into one field?
1066
How do I display the results of MySQL queries in CSV format?
697
Finding duplicate values ​​in MySQL
0
Week / month data search in MYSQL



All Articles
Loading...
X
Show
Funny
Dev
Pics