Domanda

I'm working on a report in Crystal Reports XI that allows someone to filter help desk tickets using a number of optional dynamic parameters. If I make a selection for each parameter it returns the expected results, but if I leave out any of the parameters it doesn't return anything and when I look at the SQL query it says, "No SQL Query is used because the record selection formula returns no records." I currently have the following code for Record Selection:

{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}
)

To me, this seems like it should work and if I leave out the If statement to verify the parameters have values I get an error so it seems like the HasValue is working properly. Any ideas?

È stato utile?

Soluzione

Your problem stems from not explicitly handling the optional parameter configurations. It's easy to run into this problem when using if-statements in the record selection formula. Instead, explicitly handle the cases where the parameters DO and DO NOT have values. Something like this:

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

Doing it this way effectively tells CR to just ignore the parameter if is doesn't have a value, otherwise select records based on what was entered in those parameters.

Altri suggerimenti

The Record Selection formula indicates whether a record must be used, or not, by returning true or false. With that in mind, if some value is informed, the formula must return True if it meets some criteria. If nothing is informed on the filter, the formula must always return True.

Try something like this:

{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)) 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top