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'

有帮助吗?

解决方案

  • 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).

其他提示

Option I: create two columns: one for each bar code. Do this in Crystal Reports.

Remove the PartPC table, replacing it with two SQL Expression fields:

// {%EAN-8}
(
  SELECT ProdCode
  FROM   PartPC
  WHERE  ProdID=Product.ProdID
  AND    PCType='EAN-8'
)

// {%EAN-13}
(
  SELECT ProdCode
  FROM   PartPC
  WHERE  ProdID=Product.ProdID
  AND    PCType='EAN-13'
)

Then create a formula field to display the appropriate one:

// {@barcode}
If Not(Isnull({%EAN-13})) Then
  {%EAN-13}
Else
  {%EAN-8}

Option II: alter the SQL to create to scalar-valued fields. Do this in your dataset or in a Command object (Crystal Reports).

SELECT  Product.*,
    (
      SELECT ProdCode
      FROM   PartPC
      WHERE  ProdID=Product.ProdID
      AND    PCType='EAN-8'
    ) EAN_8,
    (
      SELECT ProdCode
      FROM   PartPC
      WHERE  ProdID=Product.ProdID
      AND    PCType='EAN-13'
    ) EAN_13
FROM  Product
...
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top