I have an sql query like this, its giving a syntax error but I couldn’t find what it was:
CREATE VIEW
vw_hs_hr_wf_main_data AS
select mo.wfmod_id,
mo.wfmod_name,
mo.wfmod_view_name,
ty.wftype_code,
ty.wftype_description,
ty.wftype_table_name,
ty.wftype_view_name,
ma.wfmain_id,
ma.wfmain_sequence,
CASE
WHEN ap.wf_main_app_employee IS NULL
THEN ma.wfmain_approving_emp_number
ELSE ap.wf_main_app_employee
END CASE AS wfmain_approving_emp_number,
ma.wfmain_flow_id,
ty.wftype_update_field,
ty.wftype_assembly,
ty.wftype_assembly_class,
ma.wfmain_previous_id,
ty.wftype_cancelmain_field,
ma.wfmain_application_date,
ty.wftype_cancelstatus_field,
ty.wftype_appmain_field,
ty.wftype_bulk_app_flg,
ty.wftype_sort_field_name
FROM hs_hr_wf_module mo INNER JOIN hs_hr_wf_type ty
ON mo.wfmod_id = ty.wfmod_id
INNER JOIN hs_hr_wf_main ma
ON ty.wftype_code = ma.wftype_code
LEFT JOIN hs_hr_wf_main_app_person ap
ON ma.wfmain_id = ap.wfmain_id
AND ma.wfmain_sequence = ap.wfmain_sequence
WHERE (ma.wfmain_iscomplete_flg = 0);
The error message:
#1064 – 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 ‘CASE AS wfmain_approving_emp_number, ma.wfmain_flow_id, ty.wftype_update_fiel’ at line 11
You don’t need
END CASEto close theCASE, justEND:A better choice in your case would be a
COALESCEcall: