0

我一直在尝试让附加查询工作,但我不断收到错误消息,指出每当我在查询中使用超过 1 个参数时,都会附加 0 行。这是为了一个

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

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(无论哪个参数它都可以正常工作)我已经验证了参数具有正确的格式。

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

4

1 回答 1

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表中的任何行?

于 2013-07-05T17:17:00.067 回答