Solved

Crystal SQL expression using parameters

Posted on 2011-03-25
5
765 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 101

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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