Solved

Crystal SQL expression using parameters

Posted on 2011-03-25
5
764 Views
Last Modified: 2012-05-11
Experts,


I have to write a SQL expression to get amount summary like this
(select sum(ORTRXAMT) FROM dbo.RM20101 where DOCNUMBR = {?pDocnum}  )

it tell me syntax error or access violation. What is the problem?

my system is windows 7 and CR XI.

Please help me out.

Thanks.

lanac
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
  • 3
5 Comments
 
LVL 26

Accepted Solution

by:
Kurt Reinhardt earned 150 total points
ID: 35215294
You can't use parameters within a SQL Expression.  SQL Expressions can only be written against actual database fields, not parameters or formulas.  That being said, if you're using that parameter to return a single document number in your primary recordset, you won't need to use a parameter anyway:

(select sum(ORTRXAMT) FROM dbo.RM20101 where DOCNUMBR = "table"."docnum"  )

Open in new window


In this scenario, the SQL expression is pulling data from RM20101 and passing in the document number from the detail record in the report to the subquery.  The quotes around the table and field for the document number indicate that it was added to the query by inserting it directly from the field tree in the SQL Expression Editor. Please note, this approach only works if you are reporting against a database that allows Crystal Reports to pass in correlated elements in a SQL Expression.  SQL Server, DB2 and even Access allow it.  Oracle does not.

~Kurt
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 100 total points
ID: 35215431
Are you pulling your data from RM20101?

Are you pulling data you don't want summed or in some other way limiting the data being pulled?

It would seem you could either pull the SUM in the query itself or simply use a summary function in the report to get the sum.

mlmcc
0
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 35215497
Assuming the user isn't pulling data from RM20101 in the main report, this is a way to get an aggregate value from a related table without having to join the entire table in the main report.  It's basically a subquery at the record level.  I often use SQL Expressions and/or subqueries (if I'm writing true SQL) to "flatten" my data into a single record, for example.

~Kurt
0
 

Author Closing Comment

by:lanac222
ID: 35215634
Thanks, guys.

Did you say parameter never worked in Sql expression? I remember it was working just not date value, string and number parameter is OK.

But anyway, I change the sql expression with subquery instead of parameter.
0
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 35215906
They never work with SQL Expression fields.  Simplest way to demonstrate is for you to expand the Field Tree in the SQL Expression Editor - what you see available is what you have to work with :)

Glad you got it working!

~Kurt
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

726 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