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

If...Then Text Condition and Numeric Result

Status
Not open for further replies.

KrystlDuk

Programmer
May 19, 2006
6
US
Okay, I'm at a loss, and hope that someone here can give me a hand with this problem.
I'm using CR 9.0 and am working on a report that needs dynamic sorting abilities.
I have created a parameter (?SortBy) with 4 choices
('Course Name', 'Course Number', 'Course Group', 'Course Duration').
Then I have made a group (@SortBy) that is as follows:

IF{?Sorted By}='Course Name' Then (Courses.CourseName}
Else
IF{?Sorted By}='Course Number'Then (Courses.CourseNumber}
Else
IF{?Sorted By}='Course Group'Then (Courses.CourseGroup)
Else
IF{?Sorted By}='Course Duration'Then (Courses.Duration)

Unfortunately, the Courses.Duration is a number field, so I get the error that a string is required whenever I try to compile it. I tried using TOTEXT(Courses.Duration), but by doing this it of course turns the number to text, and will not sort 1,2,3,4,5,6,7,8,9,10 but instead 1,10,100,2,21, etc. Anyone know how I can get around this?

Any help is much appreciated. :)

Thanks in advance,
KrystlDuk
[ponytails2]
 
If you set it to:

TOTEXT({Courses.Duration},"000")
//add enough zeros to match the maximum field length

...it will sort correctly. You could use the formula for sorting or grouping, but use the actual field for display.

The other thing you could is set up two groups, one with:

Select {?Sorted By}
Case 'Course Name' : (Courses.CourseName}
Case 'Course Number': (Courses.CourseNumber}
Case 'Course Group': (Courses.CourseGroup)
default : ""

The second formula would look like:

if {?Sorted By} = 'Course Duration' Then (Courses.Duration)

Then you could conditionally suppress the group headers also using the parameter.

-LB
 
Thanks a million!! Works like a charm! I'm sorry for asking a question with such a simple answer. But I appreciate your quick reponse, it was most helpful.

Sincerely,
KrystlDuk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top