SELECT u.id,u.email,u.dateCreated,DATE(NOW()) as date_now,c.name, CASE c.name WHEN "M2M" THEN 'MONTH' ELSE "YEAR" END as type_value FROM users u JOIN contract_type c ON u.contract_type = c.id HAVING date_now > u.dateCreated + INTERVAL CONCAT("1",type_value) 

Swears at the Concat, where the mistake made

    1 answer 1

    After the word INTERVAL and the number should be the keyword (day, month, year) and not a variable or expression.

    Try this:

     HAVING date_now > CASE type_value WHEN "YEAR" THEN date_add(u.dateCreated, INTERVAL 1 YEAR) WHEN "MONTH" THEN date_add(u.dateCreated, INTERVAL 1 MONTH) END