Sql server 如何在SQL Server 2012中为字符串指定十进制值

Sql server 如何在SQL Server 2012中为字符串指定十进制值,sql-server,Sql Server,我正在将Crystal Reports中的公式转换为Sql视图 生成十进制输出的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

我正在将Crystal Reports中的公式转换为Sql视图

生成十进制输出的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)

您可以使用
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...

现在您缺少有关表如何联接的详细信息。似乎您正在尝试比较三个不同表中的数据(账户信息、机构、vAM\U CRG\U贷款\U官员\U姓名)。

非常感谢。我在“from”中添加了适当的表,并应用了适当的联接。多谢各位@GaryClements如果此答案对您有效,请单击答案旁边的复选标记