【问题标题】:Crystal Reports filtering using optional parametersCrystal Reports 过滤使用可选参数
【发布时间】:2016-03-12 02:58:48
【问题描述】:

我正在处理 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 似乎工作正常。有什么想法吗?

【问题讨论】:

    标签: crystal-reports


    【解决方案1】:

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

    ...
    (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 如果 is 没有值则忽略该参数,否则根据在这些参数中输入的内容选择记录。

    【讨论】:

      【解决方案2】:

      记录选择公式通过返回 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)) 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-06
        • 1970-01-01
        相关资源
        最近更新 更多