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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort by multiple fields with parameters.

Status
Not open for further replies.

cocopud

Technical User
Jan 8, 2002
139
US
We have quite a few reports that we already adding some sorting to; however, the users are asking for additional sorting, but since I am not sure what they would want I was wondering if it would be possible to add a parameter from which they could add multiple options. For instance, one user may want to sort by fields a, b and d, where as another user may want to sort by fields c, d and a. I found an old post that shows how to create a sort parameter listed below, but is there anyway to expand on this so that the user can select more than one option.

Create a string parameter {?sort} with options of process, subprocess, control and dimension. Then create a formula {@sortselected}:

select {?sort}
case "process" : {table.process}
case "subprocess" : {table.subprocess}
case "control" : {table.control}
case "dimension" : {table.dimension}
default : ""

Then go to report->record sort->and add {@sortselected} as your sort field.
 
What's the question? What you've shown should work, but if it doesn't then you could do it by a set of If.. then ... else commands.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
You can use this same approach, except set up the parameter to allow multiple values. Then create one formula for each level of sorting like this:

//{@Sort1}:
select {?sort}[1]
case "process" : {table.process}
case "subprocess" : {table.subprocess}
case "control" : {table.control}
case "dimension" : {table.dimension}
default : ""

//{@Sort2}:
if ubound({?sort}) >= 2 then
select {?sort}[2]
case "process" : {table.process}
case "subprocess" : {table.subprocess}
case "control" : {table.control}
case "dimension" : {table.dimension}
default : ""

//{@Sort3}:
if ubound({?sort}) >= 3 then
select {?sort}[3]
case "process" : {table.process}
case "subprocess" : {table.subprocess}
case "control" : {table.control}
case "dimension" : {table.dimension}
default : ""

//etc. Add these as your sort fields in order. You might also want to create a formula for the report header that shows the sorting selections:

join({?sort},", ")

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top