Added screenshot of the report query that throws the fatal error, and the manually crafted query how it should be (tested in phpmyadmin).
For a reason I cannot grasp when the customfield is selected the relevant LEFT JOIN is not added in civicrm 4.7.x
#QUERY FROM CIVICRM 4.7.x (4.7.1/4.7.2)
SELECT SQL_CALC_FOUND_ROWS contact_civireport.sort_name as civicrm_contact_sort_name, contact_civireport.id as civicrm_contact_id, value_drijfveren_69_civireport.motivatie_337 as civicrm_value_drijfveren_69_custom_337, value_cv_118_civireport.welke_jaren_mee_als_deelnemer__376 as civicrm_value_cv_118_custom_376
FROM civicrm_contact contact_civireport
LEFT JOIN civicrm_address address_civireport
ON (contact_civireport.id = address_civireport.contact_id AND
address_civireport.is_primary = 1 )
LEFT JOIN civicrm_value_drijfveren_69 value_drijfveren_69_civireport
ON value_drijfveren_69_civireport.entity_id = contact_civireport.id
WHERE ( contact_civireport.gender_id IN (2) ) AND contact_civireport.is_deleted = 0
ORDER BY contact_civireport.sort_name ASC LIMIT 0, 50
[nativecode=1054 ** Unknown column 'value_cv_118_civireport.welke_jaren_mee_als_deelnemer__376' in 'field list']
#PROPER QUERY (manually added last LEFT JOIN):
SELECT SQL_CALC_FOUND_ROWS contact_civireport.sort_name as civicrm_contact_sort_name, contact_civireport.id as civicrm_contact_id, value_drijfveren_69_civireport.motivatie_337 as civicrm_value_drijfveren_69_custom_337, value_cv_118_civireport.welke_jaren_mee_als_deelnemer__376 as civicrm_value_cv_118_custom_376
FROM civicrm_contact contact_civireport
LEFT JOIN civicrm_address address_civireport
ON (contact_civireport.id = address_civireport.contact_id AND
address_civireport.is_primary = 1 )
LEFT JOIN civicrm_value_drijfveren_69 value_drijfveren_69_civireport
ON value_drijfveren_69_civireport.entity_id = contact_civireport.id
LEFT JOIN civicrm_value_cv_118 value_cv_118_civireport
ON value_cv_118_civireport.id = contact_civireport.id
WHERE ( contact_civireport.gender_id IN (2) ) AND contact_civireport.is_deleted = 0
ORDER BY contact_civireport.sort_name ASC LIMIT 0, 50
So the line:
LEFT JOIN civicrm_value_cv_118 value_cv_118_civireport
ON value_cv_118_civireport.id = contact_civireport.id
is not added to the query when the custom field is selected.
causing a fatal error:
[nativecode=1054 ** Unknown column 'value_cv_118_civireport.welke_jaren_mee_als_deelnemer__376' in 'field list']
Added screenshot of the report query that throws the fatal error, and the manually crafted query how it should be (tested in phpmyadmin).
For a reason I cannot grasp when the customfield is selected the relevant LEFT JOIN is not added in civicrm 4.7.x
#QUERY FROM CIVICRM 4.7.x (4.7.1/4.7.2)
SELECT SQL_CALC_FOUND_ROWS contact_civireport.sort_name as civicrm_contact_sort_name, contact_civireport.id as civicrm_contact_id, value_drijfveren_69_civireport.motivatie_337 as civicrm_value_drijfveren_69_custom_337, value_cv_118_civireport.welke_jaren_mee_als_deelnemer__376 as civicrm_value_cv_118_custom_376
FROM civicrm_contact contact_civireport
LEFT JOIN civicrm_address address_civireport
ON (contact_civireport.id = address_civireport.contact_id AND
address_civireport.is_primary = 1 )
LEFT JOIN civicrm_value_drijfveren_69 value_drijfveren_69_civireport
ON value_drijfveren_69_civireport.entity_id = contact_civireport.id
WHERE ( contact_civireport.gender_id IN (2) ) AND contact_civireport.is_deleted = 0
ORDER BY contact_civireport.sort_name ASC LIMIT 0, 50
[nativecode=1054 ** Unknown column 'value_cv_118_civireport.welke_jaren_mee_als_deelnemer__376' in 'field list']
#PROPER QUERY (manually added last LEFT JOIN):
SELECT SQL_CALC_FOUND_ROWS contact_civireport.sort_name as civicrm_contact_sort_name, contact_civireport.id as civicrm_contact_id, value_drijfveren_69_civireport.motivatie_337 as civicrm_value_drijfveren_69_custom_337, value_cv_118_civireport.welke_jaren_mee_als_deelnemer__376 as civicrm_value_cv_118_custom_376
FROM civicrm_contact contact_civireport
LEFT JOIN civicrm_address address_civireport
ON (contact_civireport.id = address_civireport.contact_id AND
address_civireport.is_primary = 1 )
LEFT JOIN civicrm_value_drijfveren_69 value_drijfveren_69_civireport
ON value_drijfveren_69_civireport.entity_id = contact_civireport.id
LEFT JOIN civicrm_value_cv_118 value_cv_118_civireport
ON value_cv_118_civireport.id = contact_civireport.id
WHERE ( contact_civireport.gender_id IN (2) ) AND contact_civireport.is_deleted = 0
ORDER BY contact_civireport.sort_name ASC LIMIT 0, 50
So the line:
LEFT JOIN civicrm_value_cv_118 value_cv_118_civireport
ON value_cv_118_civireport.id = contact_civireport.id
is not added to the query when the custom field is selected.
causing a fatal error:
[nativecode=1054 ** Unknown column 'value_cv_118_civireport.welke_jaren_mee_als_deelnemer__376' in 'field list']