我有这样的Case-When
条款;
(CASE WHEN A.YAZ_ADRES IS NULL
THEN (B.IS_ADRES1 +' '+B.IS_ADRES2)
ELSE A.YAZ_ADRES END)
我想在THEN
例如;
(CASE WHEN A.YAZ_ADRES IS NULL
THEN (IF B.TUZ = 'T' THEN (B.IS_ADRES1 +' '+B.IS_ADRES2) ELSE ((B.EV_ADRES1 +' '+B.EV_ADRES2)))
ELSE A.YAZ_ADRES END)
如何在Case-When
中使用嵌套条件?
答案 0 :(得分:3)
嵌套另一个CASE
而不是IF
答案 1 :(得分:3)
您可以使用CASE WHEN ... THEN ... (WHEN ... THEN ...)+ ELSE ... END
。它返回匹配THEN
条件的第一个的WHEN
表达式:
CASE WHEN A.YAZ_ADRES IS NULL AND B.TUZ = 'T'
THEN B.IS_ADRES1 +' '+B.IS_ADRES2
WHEN A.YAZ_ADRES IS NULL
THEN B.EV_ADRES1 +' '+B.EV_ADRES2
ELSE A.YAZ_ADRES
END
答案 2 :(得分:1)
(CASE WHEN A.YAZ_ADRES IS NULL
THEN (CASE WHEN B.TUZ = 'T' THEN (B.IS_ADRES1 +' '+B.IS_ADRES2) ELSE ((B.EV_ADRES1 +' '+B.EV_ADRES2)) END)
ELSE A.YAZ_ADRES END)
答案 3 :(得分:1)
您可以像这样嵌套CASE
子句:
(CASE WHEN A.YAZ_ADRES IS NULL
THEN
(CASE WHEN B.TUZ = 'T'
THEN (B.IS_ADRES1 +' '+B.IS_ADRES2)
ELSE ((B.EV_ADRES1 +' '+B.EV_ADRES2))
END)
ELSE A.YAZ_ADRES
END)