?
Solved

Crystal SQL expression using parameters

Posted on 2011-03-25
5
Medium Priority
?
767 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 450 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 300 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

770 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