2013-04-19 2 views
0
내가 MySQL의에서 다음 Case 문에 문제가 오전

: 나는 오류 '예기치 않은 다음' 사람이 조언 수를 얻을 수MySQL- 케이스 상태 오류

CASE 
    WHEN 
    ((SUBSTRING_INDEX('Provider - Remote Client - North', '-', -2) = ('Provider - Remote Client - North')) then SUBSTRING_INDEX('Provider - Remote Client - North', '-', -1) 
    ELSE SUBSTRING_INDEX('Provider - Remote Client - North', '-', -2) 
END CASE 

을?!? 감사합니다.

+0

우선은 누락 된 브라켓입니다 – Xavjer

답변

1

당신은 WHEN에 괄호를하고 END 후 추가 CASE이 : 내가 볼

CASE 
    WHEN 
     SUBSTRING_INDEX('Provider - Remote Client - North', '-', -2) = 'Provider - Remote Client - North' 
    THEN SUBSTRING_INDEX('Provider - Remote Client - North', '-', -1) 
    ELSE SUBSTRING_INDEX('Provider - Remote Client - North', '-', -2) 
END 
1

필요한 경우에만 괄호를 사용하십시오. 너무 많은 것이 있습니다.

이 올바른 쿼리입니다 :

CASE 
    WHEN 
    SUBSTRING_INDEX('Provider - Remote Client - North', '-', -2) = 'Provider - Remote Client - North') 
     THEN SUBSTRING_INDEX('Provider - Remote Client - North', '-', -1) 
    ELSE SUBSTRING_INDEX('Provider - Remote Client - North', '-', -2) 
END CASE