0

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'

4

2 回答 2

2
  • 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).
于 2013-07-03T11:55:43.277 回答
0

选项 I:创建两列:每个条码一列。在 Crystal Reports 中执行此操作。

删除 PartPC 表,将其替换为两个 SQL 表达式字段:

// {%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'
)

然后创建一个公式字段以显示适当的字段:

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

选项二:更改 SQL 以创建标量值字段。在您的数据集或命令对象(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
...
于 2013-07-02T16:41:43.533 回答