V
V
Vampire0162021-05-03 21:07:28
MySQL
Vampire016, 2021-05-03 21:07:28

How to update a table one row at a time with a selection of CASE conditions?

I wrote a query to update the `DateClose` field in the `Work` table, which, depending on the presence or absence of a value in the `DateClose` field at the index `Work`.id = 6, should change the values ​​from NULL to '2021-04-26 21:34:30' and back...

When executed, it matches one line at a time (as expected) but no changes occur. Where did I go wrong?

UPDATE `Work` SET `DateClose` = ( CASE `DateClose` WHEN `DateClose` IS NULL THEN `DateClose` = '2021-04-26 21:34:30' ELSE `DateClose` = NULL END ) WHERE `Work`. id = 6;

The `DateClose` field has the DateTime format...

Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-05-03
@Vampire016

UPDATE `Work`
   SET `DateClose` = ( CASE WHEN `DateClose` IS NULL THEN '2021-04-26 21:34:30' END )
 WHERE `Work`.id = 6;

Wrong on a lot of things. Read carefully about the CASE statement (not to be confused with CASE statement - this is not your case)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question