CREATE TABLE `test_table1` (
  `CLOSE_YN` varchar(10) COLLATE utf8_bin DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ;


CREATE TABLE `test_table2` (
  `ap_close_to` varchar(8) COLLATE utf8_bin DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ;

drop function FC_LD_SYSTOLOC_TEST;

DELIMITER $$
CREATE  FUNCTION `FC_LD_SYSTOLOC_TEST`(`P_DC_CD` VARBINARY(50), `P_SYS_DATE` DATETIME) RETURNS datetime
    DETERMINISTIC
    SQL SECURITY INVOKER
BEGIN
  DECLARE V_SYS_DATE DATETIME;


SELECT now()   AS LOC_DATE
INTO V_SYS_DATE
;

  RETURN v_sys_date ;

END $$


update test_Table1 S 
JOIN
(
SELECT CASE WHEN DATE_FORMAT( FC_LD_SYSTOLOC_TEST('F01', NOW()) , '%Y%m%d') <= CLOSE_YMD THEN '99991231'
										ELSE '' END ACCOUNT_APPLY_YYYYMMDD
										FROM (
										      select  case  when  'AP'='AP' then  ap_close_to   end  AS CLOSE_YMD
											 	from test_table2
										     ) A 
) X  			
 SET S.CLOSE_YN = ''
where 1=1;