开发者

How do I dynamically select parameter with crystal report

I have been working on getting a report out for long without success.

I have a report that select based on parameter fields of date and boolean. Currently I have to create 3 reports. One based on dates, one based on the boolean and one based on both.

However, I want my report to be able to select all dates if the u开发者_运维技巧ser does not input date in the parameter or select all booleans if user does not select one.

Currently I used this

if ({?Start Date} = DateTimeValue('') or {?End Date} =DateTimeValue('')) then
   {rectReport.Call date} in DateTimeValue ('1753-01-01 00:00:00') to CurrentDateTime
else 
   ({rectReport.Call date} in {?Start Date} to {?End Date}) and {rectReport.EngineDown} = {?Engine Down}

The basic Idea I am looking for is that the user can decide to select only one parameter instead of the two.

Any help will be highly appreciated. Thanks,

Bimbo


In Crystal 2008 you have the option of making parameters optional. What you could do is create one report with both parameters and then set both parameters as optional. In your record selection formula you could do something like this:

(if  (HasValue({?Startdate}) and HasValue({?Enddate}))
        then {table.datefield} in {?Startdate} to {?Enddate}
    else {table.datefield} in {defaultstartdate} to {defaultenddate})

and (if HasValue({?BoolParam}) then {table.boolfield} = {?BoolParam}
    else {table.boolfield} = {defaultbool})

If you wanted to select ALL tables if the user did not input the parameter, you could just omit the else-statements.

(note: Sorry if that syntax isn't correct (I am just getting back into CR again), but you get the idea.)

EDIT: Since optional parameters aren't available in CR10, couldn't you just use parameter default values for the dates instead? For the boolean, you could just make a parameter with 3 values: true, false, and "all" and then default to the "all" value when running the report.


I don't know your particular situation, but the way we handle this (specifically for Defined Periods vs User-specified-Date-Range) is through being able to set defaults.

Our main environment is BOE XI.

Our parameters might be ReportPeriod (String Variable) and CustomDates (DateTime Range, but will work as two discrete dates)

Example params for ReportPeriod might be 1 Day 7 Days Last Month Custom Dates

Formulas are used to calculate date limits that will be used in the record selection. I start with the END DATE, as it is convenient for our period reports.

@EndDate
  Select ?ReportPeriod
    Case
       "1 Day", "7 Days"   : CurrentDate
          // Conveniently defaults to MIDNIGHT
       "Last Month"  : Maximum(LastFullMonth)
       "CustomDates" : Maximum(?CustomDates)
          // Or discrete parameter for end date
       default : CurrentDate

@BeginDate
  Select ?ReportPeriod
    Case
       "1 Day"  :  DateAdd("d", -1, @EndDate)
       "7 Days" :  DateAdd("d", -7, @EndDate)
       "Last Month"  : Minimum(LastFullMonth)
       "CustomDates" : Minimum(?CustomDates)
          // Or discrete parameter for end date
       default : DateAdd("d", -1, @EndDate)

And, let me caution against using CurentDateTime unless necessary. Every time you try to step through the report, the selection will have changed: 5:01:10 PM ... 5:01:16 PM ... 5:01:24 PM ...

When publishing a report, we set default date (it doesn't matter what, it's only used for CUSTOM and the customer resets it then), and a default ReportPeriod.

The report can be scheduled periodically (based on ReportPeriod) and it will always run. If the user wants to do custom dates (historic reporting, etc.), then they can chose that for report period, and then set whatever start and end dates they need.

Helpful?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜