Solved

how to use parameters in SQL Expression field

Posted on 2007-03-27
7
368 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now