我在MS Access查询中使用switch()函数进行条件更新。以下是我的查询
UPDATE T_Generated_OpportunityLine SET PlContact_c = Switch(
LowestlevelValue_c='PTFDS - FD ENCLOSURE SYSTEMS',Select OpportunityLine_PostCode.SESA from OpportunityLine_PostCode,T_Generated_OpportunityLine where OpportunityLine_PostCode.Postcode=T_Generated_OpportunityLine.Selected_Zip AND
OpportunityLine_PostCode.OpptyLine_Ref='PTFDS',
LowestlevelValue_c='DOOR ENTRY SYSTEM',Select OpportunityLine_PostCode.SESA from OpportunityLine_PostCode,T_Generated_OpportunityLine where OpportunityLine_PostCode.Postcode=T_Generated_OpportunityLine.Selected_Zip AND
OpportunityLine_PostCode.OpptyLine_Ref='Door Entry System'
);
我知道switch()函数的语法:
Switch ( expression1, value1, expression2, value2, ... expression_n, value_n )
我刚刚进行了一次修改,而不是传递静态值为" 值"部分我通过选择查询动态获取此值。
但是当我尝试执行查询时,它声明了一条错误消息:
The query must be an updatable query
我确信问题出在Switch()函数内的Select Statement中,但是由于我的项目,我需要这个条件更新。
任何人都可以为此提供任何合适的解决方案吗?我也想知道我们能否为"价值"传递动态价值。 Switch()语法中的部分?
答案 0 :(得分:0)
我不知道这是不是你的问题,但通常需要将子查询括在括号中:
UPDATE T_Generated_OpportunityLine
SET PlContact_c = Switch(LowestlevelValue_c='PTFDS - FD ENCLOSURE SYSTEMS',
(Select SESA
from OpportunityLine_PostCode
where OpportunityLine_PostCode.Postcode = T_Generated_OpportunityLine.Selected_Zip AND
OpportunityLine_PostCode.OpptyLine_Ref = 'PTFDS'
),
LowestlevelValue_c = 'DOOR ENTRY SYSTEM',
(Select SESA
from OpportunityLine_PostCode
where OpportunityLine_PostCode.Postcode = T_Generated_OpportunityLine.Selected_Zip AND
OpportunityLine_PostCode.OpptyLine_Ref='Door Entry System'
));
但是,我只用一个子查询来写这个:
UPDATE T_Generated_OpportunityLine
SET PlContact_c = (Select SESA
from OpportunityLine_PostCode as pc
where pc.Postcode = T_Generated_OpportunityLine.Selected_Zip AND
(T_Generated_OpportunityLine.LowestlevelValue_c = 'PTFDS - FD ENCLOSURE SYSTEMS' AND pc.OpptyLine_Ref = 'PTFDS' OR
T_Generated_OpportunityLine.LowestlevelValue_c = 'DOOR ENTRY SYSTEM' AND op.OpptyLine_Ref='Door Entry System'
)
);