How to add parameter in crystal report
In the older versions of Crystal, it wasn't possible to amend queries to include parameter values - you could only add constant values. Consequently, your amended query is selecting records from tableA where column1 is equal to the string "", not the value of parameter .
In order to select by the parameter value, reset the query to its default value - probably:
and add a condition to the Crystal record selection dialog:
(Note - no quotes in the latter condition.)
As noted above, you need to remove the parameter from the query. because it is passed to SQL exactly the way you see it when using Show Query in Crystal. If you amend the query to select * from tableA where column1=. Crystal will attempt to run that exact string as a SQL statement, and will therefore return an error - it will not attempt to substitute the value of the parameter into the SQL statement.
However, if you add a Crystal record selection condition using the parameter into the report, Crystal will attempt
to add the selection condition to SQL when running the report - if you use Show Query after adding the Crystal record selection formula, it should first prompt you for a value for your parameter, and then show you a query that includes your selection condition (with the entered value of the parameter, not the parameter name).
There are a couple of restrictions on this automatic addition of Crystal record selection conditions to SQL:
- the SQL query must be uncustomised (ie. no changes made to the default version of the query), otherwise Crystal will not try to amend the query - the customisation takes precedence. (This is why you have to reset the query to its default form.)
- the Crystal record selection criteria need to be relatively simple - a series of and conditions on database and parameter field values are normally OK, but a mixture of and and or conditions, or conditions on Crystal formula values, will probably result in Crystal not amending the query conditions.
answered Nov 7 '11 at 11:56Source: stackoverflow.com