Question:
SQL: UPDATE table SET column_x = a WHERE column_y = ' '; if I want to only update rows with omitted fields in a different column?
?
2015-02-17 15:50:58 UTC
SQL: UPDATE table SET column_x = a WHERE column_y = ' ';

or

SQL: UPDATE table SET column_x = a WHERE column_y = 'null';

or

SQL: UPDATE table SET column_x = a WHERE column_y = ('null');
Three answers:
?
2015-02-17 15:56:04 UTC
UPDATE table SET column_x = a WHERE column_y IS NULL;



'' refers to an empty string which is different to a null string, ' ' is a string containing a space and 'null' is not a null string but a string containing the word "null".
Jeff P
2015-02-17 18:41:32 UTC
If your goal is to only update rows where another column is empty, then I would do this:



UPDATE table SET column_x = a WHERE column_y = '' OR column_y IS NULL;
AJ
2015-02-18 05:52:54 UTC
agree with Jeff's answer over Fiona's. Her solution does not account for zero length string


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...