Crystal reports 公式赢得';某些字段为空时不显示

Crystal reports 公式赢得';某些字段为空时不显示,crystal-reports,crystal-reports-xi,crystal-reports-2010,Crystal Reports,Crystal Reports Xi,Crystal Reports 2010,与我的第一个问题类似。我想在包含以下字段的文本框中显示我的地址 {Company} {AddLine1} {AddLine2} {ZIP}{State}{City} {Country} 我(希望你们中的一些人)关心的是{ZIP}{City}{State}。我想要产生的是一个一致的寻址格式,这样即使在数据库中ZIP、City或State字段留空,也不会有空格或缩进。此行仍应与其余行对齐,且不缩进。我还希望在邮政编码、州和城市之间插入逗号,将它们放在不相关的地方。为此,我写了一个公式。下: If

与我的第一个问题类似。我想在包含以下字段的文本框中显示我的地址

{Company}
{AddLine1}
{AddLine2}
{ZIP}{State}{City} 
{Country}
我(希望你们中的一些人)关心的是{ZIP}{City}{State}。我想要产生的是一个一致的寻址格式,这样即使在数据库中ZIP、City或State字段留空,也不会有空格或缩进。此行仍应与其余行对齐,且不缩进。我还希望在邮政编码、州和城市之间插入逗号,将它们放在不相关的地方。为此,我写了一个公式。下:

If isnull({BILL_TO.ZIP}) or trim({BILL_TO.ZIP})= "" Then "" else {BILL_TO.ZIP}
+
(If isnull({BILL_TO.State}) or trim({BILL_TO.State})= "" Then ""
    else(If not isnull({BILL_TO.ZIP}) and length(trim({BILL_TO.ZIP})) <> 0 Then ", "        else "") + {BILL_TO.State})
+
(If isnull({BILL_TO.CITY}) or length(trim({BILL_TO.CITY})) = 0 Then ""
    else(

            If (not isnull({BILL_TO.State}) and length(trim({BILL_TO.State})) <> 0) 
                or
                (not isnull({BILL_TO.Zip}) and length(trim({BILL_TO.Zip})) <> 0)

            Then ", " else "")+ {BILL_TO.CITY}))
如果isnull({BILL_TO.ZIP})或trim({BILL_TO.ZIP})=“那么”否则{BILL_TO.ZIP}
+
(如果isnull({BILL_TO.State})或trim({BILL_TO.State})等于“”,则“”
else(如果不是isnull({BILL_TO.ZIP})和length(trim({BILL_TO.ZIP}))0,则“else”“)+{BILL_TO.State})
+
(如果isnull({BILL_TO.CITY})或length(trim({BILL_TO.CITY}))=0,则“”
否则(
If(非isnull({BILL_TO.State})和length(trim({BILL_TO.State}))0
或
(非isnull({BILL_TO.Zip})和长度(trim({BILL_TO.Zip}))0)
然后,“else”+{BILL_TO.CITY})
问题是,当只有一个城市(没有输入州或邮政编码)时,公式本身不会显示。但是,当其他人在场时,它会显示

有人能看到这个代码中的错误吗???真要命

谢谢你的帮助


期待你们的消息

这个公式中有很多if-then-else,所以很难说,但是如果它没有显示任何东西,这可能意味着你在某处使用了一个字段,而没有首先处理它的null条件。简单点的东西可能是你最好的选择:

local stringvar output;
if not(isnull({Customer.Postal Code})) then output:=trim({Customer.Postal Code}) + ', ';
if not(isnull({Customer.Region})) then output:=output + trim({Customer.Region}) + ', ';
if not(isnull({Customer.City})) then output:=output + trim({Customer.City}) + ', ';

left(output,length(output)-2)

为每个数据库字段创建公式字段。例如:

// {@CITY}
If Isnull({BILL_TO.CITY}) Then
  ""
Else 
  Trim({BILL_TO.CITY})

// {@STATE}
If Isnull({BILL_TO.STATE}) Then
  Space(2)
Else
  Trim({BILL_TO.STATE})

// {@ZIP}
If Isnull({BILL_TO.ZIP}) Then
  Space(5)  //adjust to meet your needs
Else
  Trim({BILL_TO.ZIP})
将每个公式字段嵌入到文本对象中

格式化文本对象及其字段以满足您的需要

**编辑**


如果您有数据质量问题,请在STATE和ZIP公式中解决它们(因为它们的长度是恒定的)。我会在文本对象中添加逗号和空格。

这并没有解决在ZIP、City和State之间有条件地添加空格和逗号的问题。