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!

Sorting data using a parameter 1

Status
Not open for further replies.

mciing7912

Programmer
Jul 14, 2006
16
MX
Hi,

I'm using Crystal Reports 8.5 and I was wondering if it's possible to sort the data by differents criterias! I mean, using a parameter, say to the program, if parameter equals 1, sort the information by date1, if equals 2, by date2 ....

is this possible??

thanks!
 
Yes... and it's a reasonable and reasonably common request.

First you need a parameter and you need to set default values for it. I.e. {?SortOrder} w/ default values of "Birthdate", "Hire Date", "Last Pay Date", etc. - using dates as an example.

Next, make a formula that will test for the parameter values and substitute a field for each case. I.e.,
{@SortOrder}
If {?SortOrder} = "Birthdate" then {field.birthdate}
else if {?SortOrder} = "Hire Date" then {field.hiredate}
else if {?SortOrder} = "Last Pay Date" then {field.lastpaid}
else {field.datefired}


Now you have a formula that will change it's source based on parameter.

Next group on that formula.

Voila ;-)


--
Marc Visconte
CSC
Lead RMS Developer
Crystal Reports
 
If you want to have sort options that are of different data types, then you either convert all formula results to text, or you could create separate formulas by datatype:

//{@datesort}:
if {?sort} = "Date" then
{table.date} else date(0,0,0)

//{@numbersort}:
if {?sort} = "ID" then
{table.number} else 0

//{@stringsort}:
if {?sort} = "Name" then
{table.name} else ""

Add each of these in the sort fields. If you want to group, by the formulas, add groups on each and then suppress the appropriate group section in the section expert by using a formula, e.g.,:

{?Sort} <> "Date" //to suppress the {@datesort} group header/footer

//etc.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top