This is more of a general SQL question rather than specific PHP but I couldn't find a better section to post it on!
Is there a way of doing an SQL statement that says "Replace any field in this row with a 0 if that field is a null"?
Printable View
This is more of a general SQL question rather than specific PHP but I couldn't find a better section to post it on!
Is there a way of doing an SQL statement that says "Replace any field in this row with a 0 if that field is a null"?
No, since there could be fields (like VARCHAR or BLOB) that don't accept 0 as value. In one query you could set every field to 0 (or something similar) if the field you check for in the row is null.
But you could use more than one query like
UPDATE tablename fieldname='0' WHERE fieldname=NULL
UPDATE tablename otherfield='0' WHERE otherfield=NULL
But don't rely on what I've said, I've never got deep into obscure SQL commands.
Maybe a better answer could be generated if you told us why you need to do something like this?
Surely setting a default would make their no need for a code approach, if that's what your problem is.
Maybe you could explain?