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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -