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

How to Sort Records Based on Parameter 2

Status
Not open for further replies.

trbyrne

IS-IT--Management
Jul 5, 2007
60
US
I have one report that I would like to sort different ways (I don't want to have to create five or six different reports to do this). Can I create a parameter listing the different sort options and then sort the report based on the value entered for this parameter? If I can, would you please tell me how this is done?

Thanks.
 
Yes, create a parameter called "Sort Order" with your list of options...

EXAMPLE
=======
01 - Customer Number
02 - Order Number
03 - Store Number


Then create a formula field called "Sort" which selects the datbase field that corresponds to your sort...

EXAMPLE
=======
IF {?Sort Order} = "01" THEN {table.customer_number}
ELSE
IF {?Sort Order} = "02" THEN {table.order_number}
ELSE
IF {?Sort Order} = "03" THEN {table.store_number}
ELSE 1

Then insert that "Sort" formula field into the detail section of your report (can be suppressed), and Sort or Group based on that "Sort" formula field.

 
That's great, but what I have found out is that I have three number fields and two date fields that I want to sort on. It will not allow me to mix them in my formula. Any suggestions? BTW, I'm running CR 10 developer edition.

Thank you.
 
You can either convert all fields to text in the formula or make separate formulas like this:

//{@datesort}:
if {?sort} = "StartDate" then {table.startdate} else
if {?sort} = "EndDate" then {table.enddate}

//{@numbersort}:
if {?sort} = "CustomerNo" then {table.custno} else
if {?sort} = "EmployeeID" then {table.emplID}

Add both as sort fields. If the sort criteria is not met for one of the formulas, it will not affect the sort.

-LB
 
Thank you, lbass, for your help! That solved my problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top