I need to put a Case in the Select to check if the Data I'm adding to my view is NULL, in which case I want it to just enter a zero, or not.
+1
A:
When creating your table just add NOT NULL
to the column description, e.g.
CREATE TABLE (
ID INT NOT NULL default '0'
);
Then if no data is given for the field it is set to the default value of 0 which will be retrieved when you run a SELECT query.
Jacob Wyke
2009-07-23 23:43:42
this doesn't apply if, for example, the NULL is the result of a LEFT OUTER JOIN.
longneck
2009-07-24 20:21:22
A:
You mean something like this?
SELECT IF(`field` IS NULL, 0, `field`)...
There's also "IFNULL()":
SELECT IFNULL(`field`, 0)...
Adam Bradley
2009-07-24 00:43:31
this is a classic case of misusing IF() and IFNULL() where the more generally accepted COALESCE() is a better idea.
longneck
2009-07-24 20:20:13