Question

I have a subreport in a crystal report but there are 0 records returned, but the subreport insists on pulling every order remark ever entered yet still displaying 0 remarks.

It's very odd, it says "reading records 0 of 150000" and keeps increasing.

The subreports only selection critera is the company code, the customer code and the order number. they are all passed with the "{?PM-..." thing going on.

I opened a blank subreport's preview and the SQL didn't even make mention of the selection criteria. the query run by itself would indeed show every remark.

Any thoughts on how this can happen?

Subreport Formula:

({E_ORD_H.COMP_CODE} = {?Pm-E_ORD_H.COMP_CODE})
and
({E_ORD_H.CUST_CODE} = {?Pm-E_ORD_H.CUST_CODE})
and
({E_ORD_H.ORD_NUM} = {?Pm-E_ORD_H.ORD_NUM})
Was it helpful?

Solution

When a Crystal Report behaves like that it means that there is some logic that cannot be done on the DB server, so it must be done locally. Usually this is caused by using a CR function in the record selection formula that doesn't translate into the DB's language.

In this case, I believe it is when the parameters are null that is causing it (For example, the statement {E_ORD_H.COMP_CODE}=<null> does not mean that CR will be able to anticipate this situation and substitute {E_ORD_H.COMP_CODE} is null in its place in the subreport's query. Instead, you need to explicitly check for those null-valued parameters:

not(isnull({?Pm-E_ORD_H.COMP_CODE})) 
and {E_ORD_H.COMP_CODE} = {?Pm-E_ORD_H.COMP_CODE}
and not(isnull({?Pm-E_ORD_H.CUST_CODE})) 
and {E_ORD_H.CUST_CODE} = {?Pm-E_ORD_H.CUST_CODE}
and not(isnull({?Pm-E_ORD_H.ORD_NUM}))
and {E_ORD_H.ORD_NUM} = {?Pm-E_ORD_H.ORD_NUM}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top