我有两个查询,只列出他们最终得到的字段(而不是链接,因为第一个链接了6个表)
1)qryEmployee_Order
Employee_ID
Operation_Date
"Employee Name"
"Order Name"
"Model Name"
"Operation Name"
"Wage Rate"
"Quantity Produced"
2)qryEmployee_Work
Employee_ID
Work_Date
"Employee Name"
"Work Name"
"Wage Rate"
"Hours Worked"
我工作的业务基本上有3种类型的员工。我不知道这些的正确英语术语,所以我将解释它们。:
第一个查询(qryEmployee_Order)是第一个类别,它们按照它们产生的数量支付(与所花费的小时数无关)。第二个查询(qryEmployee_Work)适用于第二类员工(基于小时工资)。
我当前的报告显示qryEmployee_Order的月度报告,其中Employee_Id是获取正确员工的过滤器,然后Operation_Date是报告本身中的标题,其中所有其他内容都被分组(即,员工在给定的内容中生成的所有内容)日期)。
我还想在Operation_Date下添加来自qryEmployee_Work的信息,以防他每小时也做一些工作。
我无法使用此功能,因为我的记录集仅设置为qryEmployee_Order。我知道子报告可能就是我正在寻找的东西,但是当我尝试这个时,我无法正确地过滤日期(即它会在所有记录中显示给定日期的qryEmployee_Work的所有记录)在qryEmployee_Order中的相同日期。
例如,如果qryEmployee_Order中的01/06下有3条记录,qryEmployee_Work中有01/06下的2条记录,它将显示qryEmployee_Order中每条记录的2条记录。
即
qryEmployee_Order row1
qryEmployee_Work ROW1
qryEmployee_Work ROW2
qryEmployee_Order row2
qryEmployee_Work ROW1
qryEmployee_Work ROW2
qryEmployee_Order row3
qryEmployee_Work ROW1
qryEmployee_Work ROW2
我想得到的是:
qryEmployee_Order row1
qryEmployee_Order row2
qryEmployee_Order row3
qryEmployee_Work ROW1
qryEmployee_Work ROW2
答案 0 :(得分:0)
一种方法是获取您希望显示的公共列的列表,然后使用union语句将所有列组合在一起,如下所示: 在没有值的情况下,使用Nz函数将零值替换为零值或者" - "表明那里没有价值
Select
Employee_ID,
Operation_Date,
"Employee Name",
"Order Name",
"Model Name",
"Operation Name",
"Wage Rate",
"Quantity Produced",
WorkName,
WageRate,
HoursWorked
From (
Select
Employee_ID,
Operation_Date,
"Employee Name",
"Order Name",
"Model Name",
"Operation Name",
"Wage Rate",
"Quantity Produced",
Nz([Work Name],"-") as WorkName,
Nz([Wage Rate],0) as WageRate,
Nz([Hours Worked],0) as HoursWorked
From qryEmployee_Order
union all
Select
Employee_ID,
Work_Date,
"Employee Name",
Nz([Order Name],"-") as OrderName,
Nz([Model Name],"-") as ModelName,
Nz([Operation Name],"-") as OperationName,
Nz([Wage Rate],0) as WageRate,
Nz([Quantity Produced],0) as QuantityProduced,
"Work Name"
"Wage Rate"
"Hours Worked"
From qryEmployee_Work
) As CombinedEmployee_Order_Work