嵌套if else在Crystal报表中的条件

时间:2014-03-19 05:31:34

标签: crystal-reports

我有一个.rpt文件,带有一个view datasource。我有四个参数用于过滤选择。我写了如下选择公式。

if ({?actype} <> "All") OR ({?actype} <> "All") OR ({?collectorname} <> "All") OR ({?batchno}<> "All") Then
(
if {?actype} <> "All" Then
   {CollectorPerformance.accountType} = {?actype};
if {?collectorname} <> "All" Then 
   {CollectorPerformance.realname} = {?collectorname};
if {?batchno} <> "All" Then 
   {CollectorPerformance.batchno} = {?batchno} 

and
{CollectorPerformance.clientid} = {?clientid}
and 
Date({CollectorPerformance.paymentdate}) >= Date({?from})
and 
Date({CollectorPerformance.paymentdate}) <= Date({?to})

)

我上面的公式问题是它不会按照realname和actType进行过滤。我理解原因是因为缺少关键词“和”。但是,它正确地过滤了batchno&gt;请问如何使其余的两个if过滤?任何帮助都会赞赏。

1 个答案:

答案 0 :(得分:1)

选择公式必须是一个长有效的布尔语句,我认为,当你说&#34;并且缺少&#34;时,你已经建议了什么。因此,为了修复前半部分,您只需将这些语句转换为一个简化的布尔语句而不是单个语句(以#39 ;;&#39;结尾的语句)。

({?actype}="All" or {?actype}={CollectorPerformance.accountType})
and
({?collectorname}="All" or {?collectorname}={CollectorPerformance.realname})
and
({?batchno}="All" or {?batchno}={CollectorPerformance.batchno})
...

对于每个参数,用户可以选择&#34;全部&#34;或输入要过滤的特定值。如果&#34;全部&#34;如果选中,语句的特定部分(看起来像{?Parameter}="All"的部分)将评估为True,并且不会进行过滤。否则,只有与输入的参数值匹配的记录才会返回True