how to use parameters in SQL Expression field

Hi Experts,

 I have a Crystal report which need to summarize value from another table using paramters entered by user and the value can only sum in a sql exprssion field. But Sql expression can not reach the parameters. e.g
(select sum(price) from InvoiceSum where Invoicedate  beteen {?sDate} and {?eDate})

Please help.


Who is Participating?
Ido MilletConnect With a Mentor Professor of MIS at Penn State Erie and Owner, Millet SoftwareCommented:
I don't know how this can be done in Crystal.  However, at least one 3rd-party UFL (see list at: allows you to use a Crystal formula to construct and return the result of an SQL statement.  That approach makes it easy to embed the parameter value inside the SQL statement.
Kurt ReinhardtConnect With a Mentor Sr. Business Intelligence Consultant/ArchitectCommented:
Unfortunately, you've run into a limitation of SQL Expression fields.  Since they're evaluated and passed to the database prior to formulas and parameters, they can't use either of those types of fields.  They can only refer to true database fields.

For your situation, however, ss the data in the other table related to the data in the main report?  If so, you could limit the data in the main report by the parameters within your record selection criteria.  Then, if you relate the data in the main report to the data in the other table through the SQL Expression you should only get records that are within the data range specified.  As an example:

//Record Selection Criteria
{table.field} in {?sDate} to {?eDate"

//SQL Expression
  field = "mainreporttable"."mainreportfield"

Unfortunately, if the data in the other table is completely unrelated AND you need to parameterize the data selection, then you might need to use a subreport.

lanac222Author Commented:
Thanks experts. I tried to use subreport. But can not make link to the subreport. Main report table date field doesn't match the date field in subreport table.

Eg. main report show user login to system multi times a day. Each day user may have vary number of transactions. How can summarize transaction amount in subreport by the date range in main report?

WHat are the date fields in each report?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.