mysql - UPDATE field with CASE statement match or do nothing to that field while still updating other fields in SQL -
i need update query change "offer_period" field (datetime) value now() if offer_period field's value greater now(). problem is, regardless of field, need update "status" field no matter what.
because status field must updated, cannot change clause include offer_period condition or status field won't update if condition not met.
with below query, else statement causing me problems. if ommit it, offer_period field value changed null if case condition not met, bad because want nothing in these instances. tried including else condition updates existing offer_period value, results 0 rows affected. i'm stuck.
thanks taking time.
josh
update listings set `status`= 'pending' , offer_period = case when offer_period > now() now() else offer_period end listing_id=1 , agent_id=1
Comments
Post a Comment