SELECT count(*)
FROM tb_Deficiency
LEFT JOIN tb_DeficiencyAssignment 
ON tb_Deficiency.col_DeficiencyID = tb_DeficiencyAssignment.col_DeficiencyID
LEFT JOIN tb_Appointment 
ON tb_DeficiencyAssignment.col_DeficiencyAssignmentID = tb_Appointment.col_DeficiencyAssignmentID 
AND (tb_Appointment.col_Active_YN = 'Yes' OR tb_Appointment.col_Active_YN IS NULL)
WHERE tb_Deficiency.col_CompletedDate = '0000-00-00'
AND tb_Deficiency.col_Centre LIKE '$var_Centre'
