【发布时间】:2015-09-04 19:59:59
【问题描述】:
我正在尝试使用 SQL 更新 Microsoft Access 中的查询。当我运行“查询表达式中的语法错误(缺少运算符)”时出现以下错误我已将以下代码添加到基本 SELECT/FROM 查询脚本的底部。
UPDATE [HRBI Query]
SET [HRBI Query].[PaySegmentMultiplier] = (CASE WHEN [PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'Above top segment' THEN 0 ELSE CASE
WHEN [PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'Below segment 1' THEN 1.35 ELSE CASE
WHEN [PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S1' THEN 1.25 ELSE CASE
WHEN [PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S2' THEN 1.15 ELSE CASE
WHEN [PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S3' THEN .90 ELSE CASE
WHEN [PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S4' THEN .60 ELSE CASE
WHEN [PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S5' THEN .40 ELSE CASE
ELSE PaySegmentMultiplier
END
END
END
END
END
END)
FROM [HRBI Query];
我是 SQL 新手。谁能解释为什么我会收到此错误以及如何解决?谢谢。
编辑:
我尝试使用 SWITCH,但仍然收到语法错误。有什么想法吗?
SELECT SWITCH([PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'Above top segment',[HRBI Query].PaySegmentMultiplier = 0,
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'Below segment 1', [HRBI Query].PaySegmentMultiplier =1.35,
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S1', [HRBI Query].PaySegmentMultiplier =1.25,
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S2', [HRBI Query].PaySegmentMultiplier =1.15,
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S3', [HRBI Query].PaySegmentMultiplier =.90,
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S4', [HRBI Query].PaySegmentMultiplier =.60,
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S5', [HRBI Query].PaySegmentMultiplier =.40, True,'Error')
FROM [HRBI Query];
编辑:我试过了,还是语法错误?
SET [HRBI Query].[PaySegmentMultiplier] = Switch (
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'Above top segment', 0,
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'Below segment 1', 1.35,
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S1', 1.25,
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S2', 1.15,
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S3', .90,
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S4', .60,
[PayGroupCountryDesc] = 'Country' AND BasePayRangeSegment = 'S5', .40, TRUE, PaySegmentMultiplier);
【问题讨论】:
-
不认为你需要其他大小写...将它们更改为只有'when'..但我认为访问不支持SQL中的大小写...也许
switch或@987654326 @? stackoverflow.com/questions/14785586/… -
你有
[HRBI Query].PaySegmentMultiplier = 0值0应该属于。请参阅下面的示例。 -
谢谢 Andre451。我尝试了 Switch,但仍然出现语法错误?我将 SET 添加到主查询代码的底部是否有区别。 (选择/从)?
-
SET 不与 SELECT FROM 一起使用。 SET 用于更新查询。我编辑了我的答案。
-
感谢您的回复。这很有帮助。