2014-05-09 80 views
2

我正在研究Crystal Reports XI中的一个报告,该报告允许某人使用大量可选动态参数筛选帮助台票证。如果我为每个参数进行选择,它会返回预期的结果,但是如果省略了任何参数,它将不会返回任何内容,并且当我查看SQL查询时,它会显示“没有SQL查询被使用,因为记录选择公式不会返回记录。“目前,我有记录选择下面的代码:使用可选参数筛选Crystal Reports

{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的工作正常。有任何想法吗?

回答

3

您的问题源于未明确处理可选参数配置。在记录选择公式中使用if语句时,很容易遇到此问题。相反,显式处理参数DO和DO不具有值的情况。事情是这样的:

... 
(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))