在另一种情况下使用Case时使用SQL

时间:2011-04-04 12:44:48

标签: sql database oracle if-statement

这是我SelectSQL部分的一部分。

(CASE WHEN GECIKME_CV(:TAR,B.HESAP_NO, 90, 9999, B.DOVIZ_KOD) AND  > 0 THEN 100 ELSE 0 END) AS PROV,

 (CASE WHEN B.HESAP_NO IN (SELECT HESAP_NO FROM S_TAKIP_MUSTERI) THEN 'E' ELSE 'H' END) AS CAT5,

我想在PROV列中添加此SQL,如果CAT5 ='E'则Prov = 0

我该如何修改此SQL

编辑:我想是那样的

(CASE WHEN GECIKME_CV(:TAR,B.HESAP_NO, 90, 9999, B.DOVIZ_KOD) AND  > 0  THEN 100 WHEN B.HESAP_NO IN (SELECT HESAP_NO FROM S_TAKIP_MUSTERI)='E' THEN 100 ELSE 0 END) AS PROV

但它不起作用。

EDIT2 :为什么这不起作用?

(CASE WHEN GECIKME_CV(:TAR,B.HESAP_NO, 90, 9999, B.DOVIZ_KOD) > 0 THEN 100 WHEN  B.HESAP_NO IN (SELECT HESAP_NO FROM S_TAKIP_MUSTERI) THEN 100 ELSE 0 END) AS PROV

1 个答案:

答案 0 :(得分:1)

您可以将查询用作子查询:

SELECT
(CASE WHEN  CAT5 = 'E' THEN 0 ELSE PROV END) PROV,
CAT5
FROM ( YOUR_QUERY ) anAlias

例如:

SELECT
(CASE WHEN  CAT5 = 'E' THEN 0 ELSE PROV END) PROV,
CAT5
FROM ( 
-- this is your query
SELECT 'E' CAT5, 5 PROV 
-- this is your query
 ) anAlias