有人可以将此语句转换为SQL Server中的CASE语句吗?
IIf((LoanBalance)=0 And CurrentPrincipal<>0 And EndPaymentDate>MaxOfPayment_Date,iif(Pledged_Loan=True,1,2), IIf(LoanBalance=0 And currentprincipal<>0,3,IIf(OffCycle_Payment=True,4,5))) AS POFF
答案 0 :(得分:0)
CASE
语句级联(意味着选择了第一个匹配条件而没有其他条件)。因此,您不必使用case
嵌套逻辑:
SELECT (CASE WHEN LoanBalance = 0 And CurrentPrincipal <> 0 And
EndPaymentDate > MaxOfPayment_Date and
Pledged_Loan = True
THEN 1
WHEN LoanBalance = 0 And CurrentPrincipal <> 0 And
EndPaymentDate > MaxOfPayment_Date
THEN 2
WHEN LoanBalance = 0 And CurrentPrincipal <> 0
THEN 3
WHEN OffCycle_Payment = True
THEN 4
ELSE 5
END) AS POFF
答案 1 :(得分:0)
我认为这将是这样的事情:
CASE WHEN LoanBalance=0
And CurrentPrincipal<>0
And EndPaymentDate>MaxOfPayment_Date
THEN CASE WHEN Pledged_Loan=True THEN 1 ELSE 2 END
WHEN LoanBalance=0
And currentprincipal<>0
THEN 3
WHEN OffCycle_Payment=True
THEN 4 ELSE 5 END END AS POFF
啊,我相信SQL Server中的布尔值会被存储为一点,所以这样就可以了:
CASE WHEN LoanBalance=0
And CurrentPrincipal<>0
And EndPaymentDate>MaxOfPayment_Date
THEN CASE WHEN Pledged_Loan=1 THEN 1 ELSE 2 END
WHEN LoanBalance=0
And currentprincipal<>0
THEN 3
WHEN OffCycle_Payment=1
THEN 4 ELSE 5 END END AS POFF
答案 2 :(得分:0)
试试这个
SELECT CASE WHEN LoanBalance = 0
AND CurrentPrincipal <> 0
AND EndPaymentDate > MaxOfPayment_Date
THEN CASE WHEN Pledged_Loan
THEN 1
ELSE 2
END
ELSE CASE WHEN LoanBalance = 0 AND currentprincipal <> 0
THEN 3
ELSE CASE WHEN OffCycle_Payment
THEN 4
ELSE 5
END
END
END AS POFF