I've been trying to figure out a query which will do the followings:
- Check
last_servicerecord and adddelivery_frequencyrecord which is day-based tonext_servicedate field in mysql. - However, if
last_serviceisNULLorEmptythen updatelast_serviceto today's date and do the step 1 afterwards.
I know how to do the step one which is the following query:
UPDATE events SET next_service = DATE_ADD(last_service,INTERVAL 14 DAY) WHERE order_product_id = 3;
But somewhat I found Step 2nd trickier. Could some one show me how to do that?
I am consuming these with PHP but I don't want to handle this part with PHP doing double query or something.
You can think what I am looking for as following:
UPDATE events SET next_service = IF last_service IS NOT NULL OR '' THEN
DATE_ADD(last_service,INTERVAL 14 DAY) ELSE SET last_service = CURRENT_DATE AND
DATE_ADD(last_service,INTERVAL 14 DAY) END IF WHERE order_product_id = 3;