Solved

Crystal SQL expression using parameters

Posted on 2011-03-25
5
762 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

831 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