假设我有以下2个表格:
表A:
CompanyCode
LocationCode
FormNumber
EmployeeNumber
...
表B:
CompanyCode
LocationCode
FormNumber
EmployeeNumber
ClaimDate
...
使用所有4个参数(CompanyCode,LocationCode,FormNumber,EmployeeNumber
)连接表A和表B.将为报告输入这4个参数。
表A中的一行在表B中可以有多行。
在Crystal Report中,对于表A中的每条记录,我只想要表B中具有最早ClaimDate的行。
使用SQL,可以使用以下方法完成:
SELECT *
FROM TableA a
INNER JOIN TableB b ON
a.CompanyCode = b.CompanyCode AND
a.LocationCode = b.LocationCode AND
a.FormNumber = b.FormNumber AND
a.EmployeeNumber = b.EmployeeNumber
WHERE a.CompanyCode = @CompanyCode AND
a.LocationCode = @LocationCode AND
a.FormNumber = @FormNumber AND
a.EmployeeNumber = @EmployeeNumber AND
b.ClaimDate IN
(SELECT MIN(b.ClaimDate)
FROM TableB b
WHERE b.CompanyCode = @CompanyCode AND
b.LocationCode = @LocationCode AND
b.FormNumber = @FormNumber AND
b.EmployeeNumber = @EmployeeNumber )
但我不太确定如何在Crystal Report中做到这一点。我尝试使用SQL Expression,但似乎SQL表达式无法传递报告输入。
答案 0 :(得分:0)
您需要在命令中创建4个参数(CompanyCode
,LocationCode
,FormNumber
,EmployeeNumber
。
命令的查询:
SELECT *
FROM TableA a
INNER JOIN TableB b ON
a.CompanyCode = b.CompanyCode AND
a.LocationCode = b.LocationCode AND
a.FormNumber = b.FormNumber AND
a.EmployeeNumber = b.EmployeeNumber
WHERE a.CompanyCode = {?CompanyCode} AND
a.LocationCode = {?LocationCode} AND
a.FormNumber = {?FormNumber} AND
a.EmployeeNumber = {?EmployeeNumber} AND
b.ClaimDate IN
(SELECT MIN(b.ClaimDate)
FROM TableB b
WHERE b.CompanyCode = a.CompanyCode AND
b.LocationCode = a.LocationCode AND
b.FormNumber = a.FormNumber AND
b.EmployeeNumber = a.EmployeeNumber )
答案 1 :(得分:0)
首先,为表A中的数据对行进行适当的分组。然后创建一个为每个组重新开始的运行总计字段(确保记录按日期排序)。验证每个明细行的运行总计是否正确后,创建一个组选择公式,显示运行总计等于1的记录。