turkinator
turkinator

Reputation: 925

Crystal Reports - Get First, Second and Third occurrence of linkedTable value

I have the following One-To-Many scenario:

One Record -> To -> Many Notes (of types X, Y and Z)

In the page for each Record, I need to include only the first 3 Notes of Type X in chronological order.

How do I do this? I've tried setting 3 subreports, but I can't tell the second and third subreport which notes have already been selected as part of the prior occurrences.

Upvotes: 0

Views: 2125

Answers (2)

shawnt00
shawnt00

Reputation: 17935

{@ResetCounter} // Place this in the group/page header where you want to restart the counter
global numbervar counter := 0;

Place this in the section suppression formula
global numbervar counter;
counter := counter + 1;
counter > 3; // if true then suppress

If you have multiple sections to suppress make sure you only increment one time. So just remove the middle line in the subsequent suppression formulas.

Upvotes: 1

Siva
Siva

Reputation: 9101

Just an extension to your solution.

  1. First select only select 3 records to be retrieved from database.

  2. Now sort either ascending or descending order in all 3 sub reports.

  3. Now in sub report 1 suppress 2 and 3 records in the same way in second sub report suppress 1 and 3 records and in sub report 3 suppress 1 and 2 records.

You can suppress the records by placing the special field Record Number and suppress condition would be

if recordnumber = 1
then true
else false

Same way for second and third records.

Upvotes: 1

Related Questions