Search code examples
crystal-reportscrystal-reports-xi

Crystal Report - Conditional selection of record


I'm using Crystal Reports XI.

My data is coming from a dataset.

I have 2 tables which are related as follows:

Product(ProdID(PK), ProdName)

ProdPC(ProdPCID(PK), ProdID(FK), PCType, ProdCode)

The 'PCType' field determins the type of barcode format the 'ProdCode' represents. (E.g. EAN13, EAN8).

In crystal reports one 'Product' can have more than one kind of barcode which means my tables end up looking like this:

Product: ("1", "Example Product 1")

ProdPC: ("0", "1", "EAN8", "01234567"), ("1", "1", "EAN13", "012345678910")

In crystal reports I only want to print 1 barcode label for per product. However because they're are 2 records in the 'ProdPC' table, I will get 2 labels being printed for this 1 product.

What I want to do is place a condition in crystal reports which states, "If EAN13 is NULL then display EAN8, ELSE display EAN13"

I do not have access to the dataset and cannot prevent the application which calls Crystal Reports to create the barcode labels from sending more than 1 record for the 'ProdPC' table.

How can I create my conditional statement, purely in 'Crystal Reports 2008'?

What I have tried so far is:

IF {PartPC.PCType} = "EAN-13" AND {PartPC.ProdCode} <> "" THEN 
    {PartPC.ProdCode}
ELSE 
    /* DISPLAY PartPC.ProdCode containing EAN8 value */
;

But I am unsure how to then tell Crystal Reports to display the 'ProdCode' value where 'PCType' is equal to 'EAN8'


Solution

    • Group your report by Product ID.
    • Order your report by PC Type descending (within Product ID).
    • Include your report details in the Product ID footer (not the details section).