需要将一个简单的数字集转换为带有if,then,else的文本

时间:2012-02-02 15:29:56

标签: crystal-reports

Crystal Reports相当新鲜。需要将数字转换为公式中的文本。这是我尝试过的以及其他几个,但是返回错误。任何有用的建议!

IF {Ref_Referrals.ReferralStatusID} = 1 then totext "Open" 
or if 2 = then totext = "Closed-Sale"
or if 3 = then totext = "Closed-Expired"
or if 4 = then totext = "Closed-No Interest"
or if 5 = then totext = "Closed-Extended"
or if 6 = then totext = "Closed-Sale(Auto)"
or if 7 = then totext = "Closed-Future Interest"
or if 8 = then totext = "Closed Not Qualified"
else totext is null

2 个答案:

答案 0 :(得分:1)

您需要为此使用CASE语句。

select {Ref_Referrals.ReferralStatusID}
 case 1 : "Open"  
 case 2 : "Closed-Sale"
 case 3 : "Closed-Expired"
 case 4 : "Closed-No Interest"
.
.
.
default : "" 

答案 1 :(得分:0)

如果您在实际的Crystal Report中执行此操作,则需要使用Switch语句。

Switch ({Ref_Referrals.ReferralStatusID} = 1, "Open",
{Ref_Referrals.ReferralStatusID} = 2, "Closed-Sale",
{Ref_Referrals.ReferralStatusID} = 3, "Closed-Expired",
{Ref_Referrals.ReferralStatusID} = 4, "Closed-No Interest",
{Ref_Referrals.ReferralStatusID} = 5, "Closed-Extended",
{Ref_Referrals.ReferralStatusID} = 6, "Closed-Sale(Auto)",
{Ref_Referrals.ReferralStatusID} = 7, "Closed-Future Interest",
{Ref_Referrals.ReferralStatusID} = 8, "Closed Not Qualified",
True, "")

如果之前的8个条件都不为真,则Switch的最后一行返回0长度的字符串。

编辑:如果由于某种原因你仍然真的想用IF THEN ELSE这样做,你需要使用嵌套的ELSE IF。但SWITCH旨在取代嵌套的ELSE IF。只是一个想法。