Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping using a parameter?

Status
Not open for further replies.

snikolaidis

Programmer
Jun 9, 2003
1
GR
Hi,
I have made a report (using CR 9.2) where I use a parameter for selecting fields.

User gives a month (values 1-12, stored in a parameter named {?month}) and each row shows data from that
specific month. The select query returns all months since there are 12 different fields in each row - price01, price02.. price12.

In my code, I have created fields which have the following form:
Code:
     if {?month}=1 then price01
else if {?month}=2 then price02
else if {?month}=3 then price03
etc..
And I use these fields in the report.

Giving one number in the beggining, the report works perfectly.

My question has to do with the possibility to use a range in the parameter (1-3, or dinstinct values 1,2,5) and create different groups, for each value of the parameter. Is this possible? How can I do it?

Thanx,
snikolaidis.
 
If I understand you correctly...there is no "month" in the database...you have just decided to use certain fields based on the month chosen by the user

if {?month}=1 then price01
else if {?month}=2 then price02
else if {?month}=3 then price03
etc..

You could create a group based on this formula but it would be sorted by price() value not by month

To get around this we will concatenate the parameter to the price to force it into the proper order

something like this

@Group1

StringVar result := ""

if {?month}=1 then
result := totext({?month},0) + totext(table.price01,0)
else if {?month}=2 then
result := totext({?month},0) + totext(table.price02,0)
else if {?month}=3 then
result := totext({?month},0) + totext(table.price03,0)
...etc..

result;

This will be your first group...you may suppress the header and footer if you wish but the data will be ordered fine



Jim Broadbent
 
My first thought would be to correct your data. Maintaining data as a date field based on it's position may seem efficient, but it will require lots of workarounds whenever you want to work with it.

The second suggestion would be to do this on the database side rather than within Crystal. The reason being that Crystal doesn't support the parsing of a parameters value to determine a field name to be selected, whereas most database languages will, including SQL.

An alternative to Jim's solution is to place all of the field on your report and use a suppression on each field based on the value of the pseudo month parameter (which I'd preload), and use something like this in the suppression formula:

not(6 in {?MyNumericParmList}) // For {table.price06}

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top