1
 SELECT dbo_job.job_date, 
        dbo_job.job, 
        dbo_job.suffix, 
        dbo_job.item, 
        qry_SumCost.SumMatlPlan, 
        qry_SumCost.SumMatlAct, 
        ([qty_released]*[fixovhd_rate])/[pcs_per_lbr_hr] AS lbr_cost_plan,       
        qry_LaborHours.fixovhd_t_lbr, 
        [fixovhd_t_lbr]/[qty_complete] AS [FG Actual Price]
  FROM  qry_SumCost 
  INNER JOIN (dbo_job 
      INNER JOIN qry_LaborHours 
          ON (dbo_job.job = qry_LaborHours.job) 
          AND (dbo_job.suffix = qry_LaborHours.suffix)) 
       ON (qry_SumCost.job_date = dbo_job.job_date) 
       AND (qry_SumCost.job = dbo_job.job) 
       AND (qry_SumCost.suffix = dbo_job.suffix)
   GROUP BY dbo_job.job_date, 
            dbo_job.job, 
            dbo_job.suffix, 
            dbo_job.item, 
            qry_SumCost.SumMatlPlan, 
            qry_SumCost.SumMatlAct, 
            ([qty_released]*[fixovhd_rate])/[pcs_per_lbr_hr],                
            qry_LaborHours.fixovhd_t_lbr, 
            [fixovhd_t_lbr]/[qty_complete]
     HAVING (((dbo_job.job_date) Between [Forms]![MainForm]![Text2] 
                                        And [Forms]![MainForm]![Text6]) 
              AND ((dbo_job.job) Like "BM0*" 
                  Or (dbo_job.job)     Like "WT0*"));

当我删除表达式 [fixovhd_t_lbr]/qty_complete] 时,它可以正常工作,但是当我包含它时,它会给我错误“此表达式输入错误,或者它太复杂而无法评估。例如,数字表达式可能包含太多许多复杂的元素。尝试通过将表达式的一部分分配给变量来简化表达式。我不明白这怎么可能被认为是复杂的。该表达式的两个元素都直接来自两个不同的表,并且本身不是表达式(以防有人想知道)。我很肯定这是由于这个原因,因为通过消除过程我偶然发现这是问题所在。

4

1 回答 1

2

您的查询没有意义。您正在使用group by,但没有聚合函数。这意味着子句中的条件having可以移动到where子句中,您可以使用它select distinct来代替。

所以,也许这会解决你的问题:

 SELECT DISTINCT dbo_job.job_date, 
        dbo_job.job, 
        dbo_job.suffix, 
        dbo_job.item, 
        qry_SumCost.SumMatlPlan, 
        qry_SumCost.SumMatlAct, 
        ([qty_released]*[fixovhd_rate])/[pcs_per_lbr_hr] AS lbr_cost_plan,       
        qry_LaborHours.fixovhd_t_lbr, 
        [fixovhd_t_lbr]/[qty_complete] AS [FG Actual Price]
  FROM  qry_SumCost INNER JOIN
        (dbo_job INNER JOIN
         qry_LaborHours 
         ON (dbo_job.job = qry_LaborHours.job) AND
            (dbo_job.suffix = qry_LaborHours.suffix)
       ) 
       ON (qry_SumCost.job_date = dbo_job.job_date) AND
          (qry_SumCost.job = dbo_job.job) AND
          (qry_SumCost.suffix = dbo_job.suffix)
WHERE (((dbo_job.job_date) Between [Forms]![MainForm]![Text2] And
                                   [Forms]![MainForm]![Text6]) And
        ((dbo_job.job) Like "BM0*" Or (dbo_job.job) Like "WT0*"));
于 2015-04-20T13:38:42.823 回答