Learning to Sort Records

Although filtering is one of the key components of an effective report, it alone is not enough. Often, to properly see the key pieces of data, a report needs to be sorted. Crystal Reports is quite flexible when it comes to sorting, allowing any field type to be sorted, as well as multiple and ascending or descending sorts. Sorting is applied using the Sort Expert.

Working with the Sort Expert

The Sort Expert is launched from a button on the Experts toolbar, and also via the Record Sort Expert item on the Report menu. Figure 7.5 shows the Sort Expert.

Figure 7.5. The Sort Expert.

graphics/07fig05.jpg

To apply sorting to the report, select a field from the list of available fields on the left side of the dialog area, and click the arrow (>) button to add that field to the sort fields list. Note that like filters, sorts can use fields both on the report and fields not otherwise used in the report.

graphics/lightbulb_icon.gif

In addition to sorting on report and database fields, you can sort on formula fields as well. Creating a formula field allows you to sort from a custom expression.


To see this in action, let's work through an example:

  1. Create a new report using the Employee table of the Xtreme Sample Database and add the First Name, Last Name, and Salary fields to the report.

  2. Initially, this report doesn't tell us a lot because the data is in seemingly random order. However, if the report were sorted by last name, it would be more useful. To accomplish this, first launch the Sort Expert.

  3. Select the Last Name field from the available fields list and click the arrow (>) button to apply a sort on it. Click OK to return to the report. Notice how the report's records are now sorted in alphabetical order by last name.

The Sort Expert allows sorting on both alphabetic and numeric fields. Let's modify this report to sort on salary instead of last name:

  1. Return to the Sort Expert and remove the current sort by selecting the Last Name field from the sort fields list and clicking the < button.

  2. Now select the Salary field and add it to the sort fields list.

  3. Alphabetic fields are usually sorted in ascending order (from A to Z), but numeric fields are often sorted both ways. In this case, select the Salary field in the Sort Fields list and click Descending for the sort direction. This will list the employees with the top salary first. Click OK to apply the sort and return to the report.

Notice that some employees have the same salary level. If you wanted to perform a secondary sort within duplicates of the primary sort field, you can simply add another sort field. These sort fields can be arranged up and down using the buttons near the top right corner of the Sort Expert.



Sams Teach Yourself Crystal Reports 9 in 24 Hours
Sams Teach Yourself Crystal Reports 9 in 24 Hours
ISBN: B003D7JUVW
EAN: N/A
Year: 2005
Pages: 230

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net