2011-04-04 119 views
0

這是Select部分的一部分,位於我的SQL中。在另一個案例中使用案例使用SQL時

(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, 

我想添加這個SQL在PROV列什麼,如果CAT5 = 'E' 然後箴= 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 
+0

你爲什麼說這是行不通的?你得到什麼錯誤信息? – DCookie 2011-04-04 14:51:40

+0

什麼版本的Oracle? – DCookie 2011-04-04 14:52:01

回答

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 
+0

用YOUR_QUERY替換您的查詢。在查詢中我給出「FROM(YOUR_QUERY)anAlias」 – 2011-04-04 13:29:00

+1

多麼完美的解決方案! – 2011-04-04 13:32:28