Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to use parameters in SQL Expression field

Posted on 2007-03-27
7
Medium Priority
?
400 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 23

Accepted Solution

by:
Ido Millet earned 500 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 500 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 101

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 101

Expert Comment

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

mlmcc
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

715 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