在查询中使用CASE WHEN获取“缺少右括号”错误

时间:2011-06-02 20:06:20

标签: sql

我在查询中使用“CASE WHEN”来获取此条件或该条件的值。我得到“Missing Right Paraethesis”错误。请告诉我要调整查询的位置。

SELECT * FROM MNDTRY_NODE_COND
 WHERE (MNDTRY_NODE_COND.OPTN_CD IN 
    CASE WHEN EXISTS  
    (SELECT * FROM MNDTRY_NODE_COND
      WHERE MNDTRY_NODE_COND.OPTN_CD IN ('GAN','4BB','RFF','U32','VVT','OAP')) 
    THEN ('GAN','4BB','RFF','U32','VVT','OAP') 
    ELSE ('*') END);

1 个答案:

答案 0 :(得分:2)

SELECT * 
FROM MNDTRY_NODE_COND 
WHERE OPTN_CD IN ('GAN','4BB','RFF','U32','VVT','OAP')
union all
SELECT * 
FROM MNDTRY_NODE_COND 
WHERE OPTN_CD = '*'
and not exists (SELECT * FROM MNDTRY_NODE_COND WHERE OPTN_CD IN ('GAN','4BB','RFF','U32','VVT','OAP'))