0

我有这个疑问:

select idCustumer, Name, Address from Customer

这给了我报告的标题,还有这个:

select idCustomer, Description, Sum(Total) as Total from Product group by Description

第一个查询运行:

 idCustomer    Name     Address
     1        Phil       Fake Av. 1234
     2        John       Fake Av. 4321

第二:

 idCustomer    Description    Sum(Total)
   1              PROD01          10
   1              PROD02          20
   2              PROD01          30

当我使用一个客户生成报告时,没关系。问题在于同一报告中有 2 个或更多客户。

我做什么?

我创建了 1 个数据集,其中有 2 个表(每个查询 1 个)通过 idCustomer 链接它们。我使用这个数据集创建了一个报告,第一个表(标题)工作正常,它打印了我的四个测试客户。

然后我添加一个子报表。

rpt.Subreports(0).SetDataSource(subReportes.Tables(1)) 'Tables(1) is 2nd Query

但这一次又一次地打印相同的信息。

我的报告:

 Customer: Phil  Address: Fake Av. 1234

 Order:
              PROD01          10
              PROD02          20
              PROD01          30

              Total           60

 Customer: John  Address: Fake Av. 4321

 Order:
              PROD01          10
              PROD02          20
              PROD01          30

              Total           60

是否有指南或链接可以让我学习如何包含此子报告以便我得到(或者是否有另一种方法来完成此操作?)

 Customer: Phil  Address: Fake Av. 1234

 Order:
              PROD01          10
              PROD02          20

              Total           30    

 Customer: John  Address: Fake Av. 4321

 Order: 
              PROD01          10

              Total           10

我正在使用 VS 2010 (VB)、SQL Server 2008 R2、Crystal Report 2010

谢谢!

4

1 回答 1

0

你的设计是完全错误的。首先,您需要像这样在 TSQL 中编写一个过程

SELECT C.idCustomer CustomerId, C.Name Name, C.Address Address, P.Description Description, P.Total Total
FROM CUSTOMER C
INNER JOIN PRODUCT P
   ON C.idCustumer = P.idCustomer

And add set this proc as the datasource for the report. Then you have to do a grouping for field, CustomerId in the report. After that you need to place the customer details in the group header section and the order details in the Details section. And also to get the total value for the you have to use the summary field in crystal reports

于 2012-07-29T09:48:19.840 回答