我正在处理 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}
)
Run Code Online (Sandbox Code Playgroud)
对我来说,这似乎应该有效,如果我省略 If 语句来验证参数是否具有值,我会收到错误消息,因此 HasValue 似乎工作正常。有任何想法吗?
您的问题源于未明确处理可选参数配置。在记录选择公式中使用 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})
Run Code Online (Sandbox Code Playgroud)
这样做有效地告诉 CR 如果没有值则忽略该参数,否则根据在这些参数中输入的内容选择记录。
| 归档时间: |
|
| 查看次数: |
10654 次 |
| 最近记录: |