Problems updating data with empty Datetime

Asked

Viewed 149 times

1

I need help with the following...

I need to update several data at once through my application, however, one of the conditions is that the field exit in the database is empty as it will be updated. The field in question is of the type Datetime.

Follows sql code:

UPDATE fluxo SET saida = SAIDA WHERE data = DATA AND saida = NULL

In case, I need to update a large number of outputs that were not fulfilled simultaneously. If I remove the condition output = NULL it updates all data at once from that date, which should not be done.

Using both NULL and empty quotes, the result is the same: nothing happens.

I appreciate the help and the attention.

1 answer

1


To verify a value NULL use to operators IS NULL and IS NOT NULL.

Example:

UPDATE `fluxo`
SET `saida` = '2017-09-21'
WHERE `data` = '2017-01-01' AND `saida` is null

See working on SQL Fiddle

Reference

  • It worked. Thank you...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.