UPDATE `sta_User` as u
JOIN imp_User as iu on iu.id = u.importSourceId
SET u.expiredOn = IF(`iu`.`paid18` = 'x', '2018-12-31', IF(`iu`.`paid17` = 'x', '2017-12-31', IF(`iu`.`paid16` = 'x', '2016-12-31', IF(`iu`.`paid15` = 'x', '2015-12-31', NULL))));

UPDATE `sta_User` as u
JOIN `sta_MembershipType` as mt on mt.id = u.membershipTypeId
SET u.expiredOn = CONCAT(YEAR(u.added) + mt.duration - 1, '-12-31')
WHERE u.importSourceId IS NULL;

