0

MSACCESS 查询:

我有一个追加查询,它从 2 个表(右连接)中提取字段。我想添加一个表达式,将一个字段中的值乘以表单上的值。查询工作正常,直到我添加计算表达式,但错误是另一个(不相关)字段不是聚合函数的一部分。如果我删除该字段,它将抱怨另一个 - 并且不断地抱怨,除非我删除计算的表达式。

作品:

INSERT INTO quote_items ( quote_unique, quote_group_a, quote_group_b, unique_product_id, DESCRIPTION, nat_price, markup, sell_price )
SELECT [Forms]![frmQUOTE].[txtQUOTE_NO] AS quote_unique, [Forms]![frmQUOTE].[cmbGROUP_A] AS quote_group_a, [Forms]![frmQUOTE].[txtGROUP_B] AS quote_group_b, ASSY_CHILDREN.UPI, ASSY_CHILDREN.DESCRIPTION, [A - MASTER PRODUCT LIST].[NAT PRICE], [Forms]![frmQUOTE]![txtMU] AS markup, ([NAT PRICE]*[markup])+[NAT PRICE] AS sell_price
FROM [A - MASTER PRODUCT LIST] RIGHT JOIN ASSY_CHILDREN ON [A - MASTER PRODUCT LIST].[UNIQUE PART NO] = ASSY_CHILDREN.PARENT_UPI
WHERE ((([A - MASTER PRODUCT LIST].[UNIQUE PART NO])=[Forms]![frmQUOTE].[cmbPART_TO_ADD]));

不起作用:

INSERT INTO quote_items ( quote_unique, quote_group_a, quote_group_b, unique_product_id, DESCRIPTION, QTY, nat_price, markup, sell_price )
SELECT [Forms]![frmQUOTE].[txtQUOTE_NO] AS quote_unique, [Forms]![frmQUOTE].[cmbGROUP_A] AS quote_group_a, [Forms]![frmQUOTE].[txtGROUP_B] AS quote_group_b, ASSY_CHILDREN.UPI, ASSY_CHILDREN.DESCRIPTION, Sum([QTY]*[Forms]![frmQUOTE]![txtQTYTOADD]) AS expr1, [A - MASTER PRODUCT LIST].[NAT PRICE], [Forms]![frmQUOTE]![txtMU] AS markup, ([NAT PRICE]*[markup])+[NAT PRICE] AS sell_price
FROM [A - MASTER PRODUCT LIST] RIGHT JOIN ASSY_CHILDREN ON [A - MASTER PRODUCT LIST].[UNIQUE PART NO] = ASSY_CHILDREN.PARENT_UPI
WHERE ((([A - MASTER PRODUCT LIST].[UNIQUE PART NO])=[Forms]![frmQUOTE].[cmbPART_TO_ADD]));

表达式添加:

expr1: Sum([QTY]*[Forms]![frmQUOTE]![txtQTYTOADD])

奇怪的是它抱怨 UPI 不是聚合的一部分,但是如果删除了这个计算的表达式(这与 UPI 无关),则返回 UPI 就好了

4

1 回答 1

0

我的建议:首先摆脱Sum()并使用...

expr1: [QTY]*[Forms]![frmQUOTE]![txtQTYTOADD]

...或者也许只是...

expr1: [Forms]![frmQUOTE]![txtQTYTOADD]

测试你的代码,看看它是否能给你想要的结果。如果没有,请编辑您的问题,向我们展示一些具有代表性的示例数据和您想要实现的目标的示例。

于 2013-04-25T07:38:57.570 回答