Problems updating data with empty DateTime

1

I need help with the following ...

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

Following sql code:

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

In this case, I need to update a large number of outputs that have not been populated simultaneously. If I remove the exit = NULL condition it updates all data at once on that date, which should not be done.

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

Thank you for your help and attention.

    
asked by anonymous 21.09.2017 / 02:26

1 answer

1

To verify a NULL value, use the IS NULL operators and IS NOT NULL operators.

Example:

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

See working in SQL Fiddle

Reference

21.09.2017 / 02:59