Here is my code:
BEGIN
SELECT SUM(
CASE WHEN first_name > '' THEN 1 ELSE 0 END AS a
CASE WHEN last_name > '' THEN 1 ELSE 0 END AS b,
CASE WHEN country > '' THEN 1 ELSE 0 END AS c,
CASE WHEN state > '' THEN 1 ELSE 0 END AS d,
CASE WHEN city > '' THEN 1 ELSE 0 END AS e)
AS total
FROM employee_profile
WHERE id = user_id_in;
END
This generates the following error:
you have an error in your SQL syntax check the manual that corresponds to your MySQL server version for the right syntax to use near xxx error for the first line.
Can anyone help with the correct syntax for this, please?
MySQL Server version: 5.5.8
SUMtakes a single argument (/ column) which it sums across multiple rows, not multiple arguments (/ columns) for a single row, this is why it’s not working.This should work: