Link to home
Start Free TrialLog in
Avatar of jwebster77
jwebster77

asked on

Add parameters to my crystal report

Hello,

I am using Crystal Reports 11 and have a connection to my database with a series of tables linked together.  I want to have two parameters added to the crystal report so that when I run the crystal report it does a query on the database.  The parameters would be named...  @FromDate and @ToDate.  With those parameters if I were to type out a where clause it would be something like this...

Where @FromDate >= DateCreated and @ToDate <= DateCreated
Avatar of WrightWay
WrightWay
Flag of Canada image

Make sure you can see the Field Explorer window.
To see this window, choose View, then Field Explorer.

In the field explorer, you will see the Parameters section, right click on it and choose New.

Give the Parameter a name, such as "MyDate"
Choose "Date" for the Value Type.
If you are using a Date field with the time included, choose DateTime
Under options, click Range, then click OK.

Now to make the report select the records you wan.t

From the menu, choose Report, then Select Expert.
From the list of database fields, choose the date in the database you want to search on.

In the first drop down box, choose "Equal To"
In the second drop down box, choose the parameter you created "MyDate"

Notes:
If you don't see your parameter listed, then it's the wrong type, try Date or DateTijme.
Sometimes dates are stored as strings.  You can browse you database field by finding it in the Exporer and right clicking and chooseing "Browse Data".
You don't have to use the >= and <= in your criteria.  Crystal is smart enough to know that if your parameter is a 'range' then 'equals' means 'within the range'





ASKER CERTIFIED SOLUTION
Avatar of crgary_tx
crgary_tx
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
CRGary is right about a slight performance hit when clicking the drop down.
This performance dip is only during report design, and not during subsequent execution of the report.
Also, I don't think it returns ALL the records, only top-n.

If you are searching on index, crystal will not retrieve all the records, only those that match the criteria, regardless of whether you use the select expert feature.  In fact the only thing you might notice is a slight pause when you click the drop-down to choose the parameter.
Since the poser of this question is a novice with Crystal reports, I suggest they do use the Select Expert feature and deal with the slight delay.  It makes no difference to the performance of the end result.
Also, by using one range parameter instead of a start and end parameter, the end user has more flexibility when entering their parameter values, such as the ability to designate if the start and end dates themselves can be done at run-time.  With two parameters, you must re-design the report to give the end user this ability.
What I meant to say is:

Also, by using one range parameter instead of a start and end parameter, the end user has more flexibility when entering their parameter values, such as the ability to designate if the start and end dates themselves are included in the criteria.  This ability is available at run-time.