Actually, you can do it in MySQL using INFORMATION_SCHEMA database. Let it be test data:
mysql> select * from test.test;
+------+------+------+------+
| id | foo | bar | baz |
+------+------+------+------+
| 1 | | NULL | 5 |
| 2 | one | NULL | 7 |
| 3 | two | four | 9 |
+------+------+------+------+
3 rows in set (0.00 sec)
And id will be our search column. Then via INFORMATION_SCHEMA.COLUMNS you'll be able to create prepared statement from SQL:
SELECT
CONCAT(
'SELECT ',
GROUP_CONCAT(
CONCAT('(', column_name,' IS NULL OR ', column_name,'="")')
SEPARATOR '+'),
' FROM test.test WHERE id=@id')
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME='test'
AND
TABLE_SCHEMA='test'
AND
COLUMN_NAME!='id';
-and use it like:
mysql> set @sql=(select CONCAT('SELECT ', GROUP_CONCAT(CONCAT('(', column_name,' IS NULL OR ', column_name,'="")') SEPARATOR '+'), ' FROM test.test WH
ERE id=@id') from information_schema.columns where table_name='test' and table_schema='test' and column_name!='id');
Query OK, 0 rows affected (0.01 sec)
mysql> prepare stmt from @sql;
Query OK, 0 rows affected (0.02 sec)
Then set your id and test:
mysql> set @id=1;
Query OK, 0 rows affected (0.00 sec)
mysql> execute stmt;
+-------------------------------------------------------------------------+
| (foo IS NULL OR foo="")+(bar IS NULL OR bar="")+(baz IS NULL OR baz="") |
+-------------------------------------------------------------------------+
| 2 |
+-------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> set @id=2;
Query OK, 0 rows affected (0.00 sec)
mysql> execute stmt;
+-------------------------------------------------------------------------+
| (foo IS NULL OR foo="")+(bar IS NULL OR bar="")+(baz IS NULL OR baz="") |
+-------------------------------------------------------------------------+
| 1 |
+-------------------------------------------------------------------------+
1 row in set (0.00 sec)
Thus, you will be able to do it in MySQL - but, really, in your case counting in application seems to be more proper solution. If you'll still use method, described above, I recommend you to add alias for result field.
nullor empty string''?