这是我的简化查询
SELECT FILTER_IS_LONGS FROM PO_OPEN_FINAL_REPORT
WHERE FILTER_IS_LONGS in( CASE WHEN testVar = 1 then 'Y' else 'N','Y' END )
我收到“缺少关键字”错误。
查询应该基本上生成IN('Y')或IN('N','Y')的IN()子句,具体取决于testVar的值
我想这与逃避'N','Y'
有关,任何帮助都会受到赞赏
答案 0 :(得分:1)
怎么样?
SELECT FILTER_IS_LONGS FROM PO_OPEN_FINAL_REPORT
WHERE
(case
when testvar=1 and FILTER_IS_LONGS in ('Y') then 1
when testvar<>1 and FILTER_IS_LONGS in ('Y','N') then 1
else 0) = 1
答案 1 :(得分:1)
完全未经测试,只是为了给你一个想法:
SELECT FILTER_IS_LONGS
FROM PO_OPEN_FINAL_REPORT
WHERE (testVar=1 AND FILTER_IS_LONGS='Y')
OR (testVar<>1 AND FILTER_IS_LONGS IN ('N','Y'))
它可能与:
相同SELECT FILTER_IS_LONGS
FROM PO_OPEN_FINAL_REPORT
WHERE FILTER_IS_LONGS='Y'
OR (testVar<>1 AND FILTER_IS_LONGS='N')