开发者

Using Case When in Another Case When with SQL

开发者 https://www.devze.com 2023-02-22 10:38 出处:网络
This is part of Select part in my SQL. (CASE WHEN GECIKME_CV(:TAR,B.HESAP_NO, 90, 9999, B.DOVIZ_KOD) AND>开发者_高级运维 0 THEN 100 ELSE 0 END) AS PROV,

This is part of Select part in my 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,

What i want to add this SQL, in PROV column, if CAT5 = 'E' Then Prov = 0

How should i modify this SQL?

EDIT: I think like that

(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

but it didn't work.

EDIT2: Why this doesn't work??

(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


you can use your query as a subquery:

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

For example :

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

精彩评论

暂无评论...
验证码 换一张
取 消