mysql - Update Field When Not Null -


The updated statement to me that updates x, y and z fields where id = xx.

I have some different x_created_datetime field in the table (for the different parts of the different held by different people / enter the record). I would like to write a single query which will update this field if it is zero, but if it is not empty then leave it alone.

So what I have:

  Update newsletter set scan_notes = "data", scan_entered_by = "some_name", scan_modified_date = "current_unix_timestamp" WHERE id = X  

what I need is a way to add the following, but still always update above:

  scan_created_date = "current_unix_timestamp" where scan_created_date empty  

I hope I can do this without a second transaction for DB. Any ideas on how to accomplish this

do this:?

  Update newsletter set scan_notes = "data", scan_entered_by = "some_name", scan_modified_date = "current_unix_timestamp", scan_created_date = COALESCE (scan_Created_date, "current_unix_timestamp") where id = X  

COALESCE function in the case selects the non-null value if datestamp will update the same value that exists, and whatever you "Replace current_unix_timestamp" .


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -