我正在将公式从Crystal Reports转换为Sql View。
产生十进制输出的SQL语法是:
if {ACCOUNT_INFO.InstitutionIdentifier}="TPOCFBOI" then 1.10 else
if {ACCOUNT_INFO.InstitutionIdentifier}="TPOBCB"then 0.50 else
if {ACCOUNT_INFO.InstitutionIdentifier}="TPOCFB"then 0.75 else
if {INSTITUTION.Region}="WMG" then .01 else
if {vAM_CRG_LOAN_OFFICER_NAME.LoanOfficerName} ="Margaret S. Smith"
then .875
What would the code look like in a Sql View to produce a decimal (3
places)?
I tried
DECLARE
@LO_Individual_Comp DECIMAL(18,3),
BEGIN
SELECT description INTO LO_Individual_Comp
FROM {ACCOUNT_INFO}
WHERE InstitutionIdentifier} = "TPOCFBOI";
DBMS_OUTPUT.PUT_LINE('1.10' || LO_Individual_Comp;
END;
If > Then Sql Equivalent to return a decimal (3 places)
答案 0 :(得分:2)
您可以使用CASE
语句
select
case
when ACCOUNT_INFO.InstitutionIdentifier ='TPOCFBOI' then 1.10
when ACCOUNT_INFO.InstitutionIdentifier ='TPOBCB' then 0.50
when ACCOUNT_INFO.InstitutionIdentifier ='TPOCFB' then 0.75
when INSTITUTION.Region = 'WMG' then .01
when vAM_CRG_LOAN_OFFICER_NAME.LoanOfficerName ="Margaret S. Smith" then .875
END as 'Decimal'
from...
现在,您缺少有关如何联接表的详细信息。看来您正在尝试比较三个不同表(ACCOUNT_INFO,INSTITUTION,vAM_CRG_LOAN_OFFICER_NAME)中的数据。