使用可选参数筛选 Crystal Reports

3

我正在使用Crystal Reports XI编写一份报告,它允许用户使用多个可选的动态参数来过滤帮助台工单。如果我为每个参数都进行选择,那么就会返回预期结果,但如果我省略任何一个参数,它就不会返回任何内容,并且当我查看SQL查询时,它会显示“没有使用SQL查询,因为记录选择公式未返回任何记录”。我目前的记录选择代码如下:

{Incident.State:} = "C" and
{Incident.Close Date & Time} in {?BDate} to {?EDate} and
If HasValue({?Group}) Then (
    {Groups.Code} = {?Group} 
) 
and
If HasValue({?Category}) Then (
    {Incident.Subject Description} = {?Category} 
)
and
If HasValue({?Staff}) Then (
    {Incident_Details.Login ID} = {?Staff} 
)
and
If HasValue({?Community}) Then (
    {Incident.Company Name} = {?Community}
)

在我看来,这似乎应该是有效的,如果我省略If语句来验证参数是否有值,那么我会得到一个错误,因此HasValue似乎正常工作。有什么想法吗?

2个回答

6

你遇到的问题是因为没有明确处理可选参数配置。在记录选择公式中使用if语句时,很容易遇到这个问题。相反,要明确处理参数有值和没有值的情况。可以像这样进行处理:

...
(not(hasvalue({?Group})) or {Groups.Code}={?Group})
and
(not(hasvalue({?Category})) or {Incident.Subject Description} = {?Category})
and
(not(hasvalue({?Staff})) or {Incident_Details.Login ID} = {?Staff} )
and
(not(hasvalue({?Community})) or {Incident.Company Name} = {?Community})

这样做有效地告诉CR,如果参数没有值,则忽略该参数;否则根据输入的参数选择记录。


1
记录选择公式决定了记录是否需要被使用,通过返回true或false来实现。如果有某个值被提供,那么该公式必须在符合一定条件时返回True。如果筛选器中没有任何信息,则该公式必须始终返回True。
尝试使用以下代码:
{Incident.State:} = "C" and
{Incident.Close Date & Time} in {?BDate} to {?EDate} and
(If HasValue({?Group}) Then (
    {Groups.Code} = {?Group} 
) else 
 (True)) 
and
(If HasValue({?Category}) Then (
    {Incident.Subject Description} = {?Category} 
) else 
 (True)) 
and (
If HasValue({?Staff}) Then (
    {Incident_Details.Login ID} = {?Staff} 
) else 
 (True)) 
and (
If HasValue({?Community}) Then (
    {Incident.Company Name} = {?Community}
) else 
 (True)) 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接