在Access 2010中使用附加查询中的多个参数

时间:2013-07-05 17:01:39

标签: sql ms-access-2010

我一直试图让一个追加查询工作,但我不断收到错误,说明每当我在查询中使用多个参数时,就会追加0行。这是为了

有问题的表有1个PK,它是一个GUID [用newid()生成值)和一个必填字段(Historical),我在查询中明确定义了这个。

INSERT INTO dbo_sales_quotas ( salesrep_id
, [year]
, territory_id
, sales_quota
, profit_quota
, product_super_group_uid
, product_super_group_desc
, class_9
, Historical
, sales_quotas_UID )

SELECT dbo_sales_quotas.salesrep_id
, dbo_sales_quotas.Year
, dbo_sales_quotas.territory_id
, dbo_sales_quotas.sales_quota
, dbo_sales_quotas.profit_quota
, dbo_sales_quotas.product_super_group_uid
, dbo_sales_quotas.product_super_group_desc
, dbo_sales_quotas.class_9
, dbo_sales_quotas.Historical
, dbo_sales_quotas.sales_quotas_UID

FROM dbo_sales_quotas
WHERE (((dbo_sales_quotas.salesrep_id)=[cboSalesRepID]) 
AND ((dbo_sales_quotas.Year)=[txtYear]) 
AND ((dbo_sales_quotas.territory_id)=[txtTerritoryID]) 
AND ((dbo_sales_quotas.sales_quota)=[txtSalesQuota]) 
AND ((dbo_sales_quotas.profit_quota)=[txtProfitQuota]) 
AND ((dbo_sales_quotas.product_super_group_uid)=[cboProdSuperGroup]) 
AND ((dbo_sales_quotas.product_super_group_desc)=[txtProductSuperGroupDesc]) 
AND ((dbo_sales_quotas.class_9)=[cboClass9]) 
AND ((dbo_sales_quotas.Historical)='No') 
AND ((dbo_sales_quotas.sales_quotas_UID)='newid()'));

即使我分配了特定值,我仍然会得到0行错误,除非我将参数数量减少到1(无论哪个参数都可以正常工作)我已经验证参数的格式正确。 / p>

谁能告诉我我做错了什么?

1 个答案:

答案 0 :(得分:1)

分解查询的SELECT部分并单独检查。我会建议一个更容易学习的简化版本......

SELECT 
    dsq.salesrep_id,
    dsq.Year,
    dsq.territory_id,
    dsq.sales_quota,
    dsq.profit_quota,
    dsq.product_super_group_uid,
    dsq.product_super_group_desc,
    dsq.class_9,
    dsq.Historical,
    dsq.sales_quotas_UID
FROM dbo_sales_quotas AS dsq
WHERE
        dsq.salesrep_id=[cboSalesRepID]
    AND dsq.Year=[txtYear]
    AND dsq.territory_id=[txtTerritoryID]
    AND dsq.sales_quota=[txtSalesQuota]
    AND dsq.profit_quota=[txtProfitQuota]
    AND dsq.product_super_group_uid=[cboProdSuperGroup]
    AND dsq.product_super_group_desc=[txtProductSuperGroupDesc]
    AND dsq.class_9=[cboClass9]
    AND dsq.Historical='No'
    AND dsq.sales_quotas_UID='newid()';

我想知道WHERE子句中的最后两个条件。 Historical字段类型位而不是文本吗?字符串'newid()'是否与表格中的任何行匹配sales_quotas_UID