2

这个查询可能非常荒谬,或者我只是有一点小错误。我不太确定。但基本上我正在尝试使用 Access 中另一个表中的数据更新一个表。给我问题的列是那些设置为“是/否”类型的列,而我试图更新它的数据设置为“文本”类型,其值为字符串“是”或“否”。

因此,如果可能的话,我对这个查询的想法是将“文本”字段大致转换为 1 或 0,具体取决于它们的 Yes 或 No 值。无论如何,足够的背景,这里是查询:

UPDATE Group_Pricing SET 
Contract_Type = (SELECT Contract_Type FROM ContractTypesFinal WHERE ContractTypesFinal.FirstGroup = Group_Pricing.GroupID), 
Hybrid_Retail =  
(SELECT CASE (SELECT RetailSpread FROM ContractTypesFinal WHERE ContractTypesFinal.FirstGroup = Group_Pricing.GroupID)
CASE "Yes"
RetailSpread = 1
CASE "No"
RetailSpread = 0), 
Hybrid_Mail =  
(SELECT CASE (SELECT MailSpread FROM ContractTypesFinal WHERE ContractTypesFinal.FirstGroup = Group_Pricing.GroupID)
CASE "Yes"
MailSpread = 1
CASE "No"
MailSpread = 0),
Hybrid_Specialty =  
(SELECT CASE (SELECT SpecialtySpread FROM ContractTypesFinal WHERE ContractTypesFinal.FirstGroup = Group_Pricing.GroupID)
CASE "Yes"
SpecialtySpread = 1
CASE "No"
SpecialtySpread = 0),
Hybrid_Rebates =  
(SELECT CASE (SELECT Rebates FROM ContractTypesFinal WHERE ContractTypesFinal.FirstGroup = Group_Pricing.GroupID)
CASE "Yes"
Rebates = 1
CASE "No"
Rebates = 0)
WHERE EXISTS (SELECT 1 FROM ContractTypesFinal WHERE ContractTypesFinal.FirstGroup = Group_Pricing.GroupID);

任何帮助深表感谢。如果这不可能,就告诉我我是个白痴。谢谢!

4

1 回答 1

3

MS Access 中不能有 CASE,可以有 IIf。

UPDATE Group_Pricing SET 
Contract_Type = 
     (SELECT Contract_Type 
      FROM ContractTypesFinal 
      WHERE ContractTypesFinal.FirstGroup = Group_Pricing.GroupID), 
Hybrid_Retail =  
IIf (SELECT RetailSpread 
     FROM ContractTypesFinal 
     WHERE ContractTypesFinal.FirstGroup = Group_Pricing.GroupID)="Yes",1,0)

<...>

请注意,MS Access 中的 YesNo 是 -1 和 0

然而,直接说:

UPDATE table1 SET AYesNo=(AText="Yes")

编辑

UPDATE Group_Pricing 
INNER JOIN ContractTypesFinal 
ON Group_Pricing.GroupID = ContractTypesFinal.FirstGroup 
SET Hybrid_Retail = (RetailSpread="Yes")

(RetailSpread="Yes")将评估为True(-1)

于 2012-07-20T21:11:24.163 回答