UPDATE eso_HSRR x set hsrr_is_use= CASE WHEN hsrr_is_use ='적용' then '1' WHEN '1' THEN '1' ELSE '0' END, hsrr_response_yn= CASE WHEN hsrr_response_yn ='예' then '1' WHEN '1' then '1' else '0' END, hsrr_response_type= CASE WHEN (SELECT y.cod_id from ecf_code y from y.cod_name=x.hsrr_response_type) IS NULL THEN x.hsrr_response_type ELSE (SELECT y.cod_id from ecf_code y from y.cod_name=x.hsrr_response_type) END , hsrr_response_level= CASE WHEN (SELECT y.cod_id from ecf_code y from y.cod_name=x.hsrr_response_level) IS NULL THEN x.hsrr_response_level ELSE (SELECT y.cod_id from ecf_code y from y.cod_name=x.hsrr_response_level) END;
문법을 잘못 넣은것같은데 에러내용을 봐선 도무지 모르겠습니다.
Error occurred during SQL query execution 이유: SQL Error [1064] [42000]: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'from y.cod_name=x.hsrr_response_type) IS NULL THEN x.hsrr_response_type ELS...' at line 3 뭐가 문젤까요?
전반적으로 문제가 많아 보입니다.
1. CASE 구문 중간에 "WHEN '1' THEN '1'" 부분은 완전 틀린 구문입니다. 제거 필요.
- 이 구문 때문에 항상 '1' 만 나옵니다. 절대로 '0' 이 나올 수 없는 구조가 되어 버립니다.
2. 코드 테이블에서 이름으로 id 찾는 서브쿼리인 듯 한데?
- 이름은 중복 가능성이 있습니다.
- 다른 항목(hsrr_response_type, hsrr_response_level)을 조건으로 주고 있다면?
- 코드 구분 항목 조건이 필요하지 않을까? 생각됩니다. (예상 코드테이블 구조 : 구분, 코드, 이름)
3. UPDATE 구문에 WHERE 절이 없습니다.
- 전체 대상 갱신을 하겟다는 것인데?
- 의도가 맞는지 의문입니다.
-- 코드 구분 조건이 필요할 것 같아 임의로 넣어 봤습니다. UPDATE eso_hsrr x LEFT OUTER JOIN ecf_code y ON y.cod_name = x.hsrr_response_type AND y.code_gubun = 'response_type' LEFT OUTER JOIN ecf_code z ON z.cod_name = x.hsrr_response_level AND z.code_gubun = 'response_level' SET hsrr_is_use = CASE hsrr_is_use WHEN '적용' THEN '1' ELSE '0' END , hsrr_response_yn = CASE hsrr_response_yn WHEN '예' THEN '1' ELSE '0' END , hsrr_response_type = IFNULL(y.cod_id, x.hsrr_response_type ) , hsrr_response_level = IFNULL(z.cod_id, x.hsrr_response_level) ;