Solved

how to use parameters in SQL Expression field

Posted on 2007-03-27
7
373 Views
Last Modified: 2012-06-27
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.

Cw

0
Comment
Question by:lanac222
7 Comments
 
LVL 22

Accepted Solution

by:
Ido Millet earned 125 total points
ID: 18800560
I don't know how this can be done in Crystal.  However, at least one 3rd-party UFL (see list at: http://www.kenhamady.com/bookmarks.html) 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.
0
 
LVL 26

Assisted Solution

by:Kurt Reinhardt
Kurt Reinhardt earned 125 total points
ID: 18800569
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
(
SELECT
  SUM(field)
FROM
  table
WHERE
  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.

~Kurt
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 18800607
0
 

Author Comment

by:lanac222
ID: 18800787
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?

0
 
LVL 100

Expert Comment

by:mlmcc
ID: 18801917
WHat are the date fields in each report?

mlmcc
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question