我对以下代码有两个问题:
UPDATE HRBI SET HRBI.PayGroupRegionCode = IIF(HRBI.PayGroupRegionCode = 'UNK' AND HRBI.CompensationGradeProfile = 'Japan JPN', 'APJ',
IIF(HRBI.PayGroupRegionCode = 'UNK' AND HRBI.CompensationGradeProfile = 'Taiwan TWN', 'APJ',
IIF(HRBI.PayGroupRegionCode = 'UNK' AND HRBI.CompensationGradeProfile = 'China CNA', 'APJ',
IIF(HRBI.PayGroupRegionCode = 'UNK' AND HRBI.CompensationGradeProfile = 'Australia AUS', 'APJ',
IIF(HRBI.PayGroupRegionCode = 'UNK' AND HRBI.CompensationGradeProfile = 'Singapore SGP', 'APJ',
IIF(HRBI.PayGroupRegionCode = 'UNK' AND HRBI.CompensationGradeProfile = 'Thailand THA', 'APJ',
IIF(HRBI.PayGroupRegionCode = 'UNK' AND HRBI.CompensationGradeProfile = 'Luxembourg LUX','EMEA',
IIF(HRBI.PayGroupRegionCode = 'UNK' AND HRBI.CompensationGradeProfile = 'Romania ROU', 'EMEA',HRBI.PayGroupRegionCode))))))));
答案 0 :(得分:1)
IIf
表达式。还可以使用模式CompensationGradeProfile IN (<list of values>)
UPDATE HRBI
SET HRBI.PayGroupRegionCode =
Switch
(
HRBI.CompensationGradeProfile IN
(
'Japan JPN',
'Taiwan TWN',
'China CNA',
'Australia AUS',
'Singapore SGP',
'Thailand THA'
), 'APJ',
HRBI.CompensationGradeProfile IN
(
'Luxembourg LUX',
'Romania ROU'
), 'EMEA',
True, HRBI.PayGroupRegionCode
)
WHERE HRBI.PayGroupRegionCode = 'UNK';
答案 1 :(得分:1)
由于您要检查PayGroupRegionCode
中的值是否已修复("UNK"
),因此您可以将其移至查询的WHERE
子句。
现在,让我们简化一下:
UPDATE HRBI
SET PayGroupRegionCode = IIF(CompensationGradeProfile = 'Japan JPN', 'APJ',
IIF(CompensationGradeProfile = 'Taiwan TWN', 'APJ',
IIF(CompensationGradeProfile = 'China CNA', 'APJ',
IIF(CompensationGradeProfile = 'Australia AUS', 'APJ',
IIF(CompensationGradeProfile = 'Singapore SGP', 'APJ',
IIF(CompensationGradeProfile = 'Thailand THA', 'APJ',
IIF(CompensationGradeProfile = 'Luxembourg LUX','EMEA',
IIF(CompensationGradeProfile = 'Romania ROU', 'EMEA', HRBI.PayGroupRegionCode))))))))
where PayGroupRegionCode = 'UNK';
现在,鉴于您只更新了两个值,我认为最简单的方法是使用两个不同的更新查询(更易于阅读和易于运行):
UPDATE HRBI
SET payGroupRegionCode = 'APJ'
WHERE PayGroupRegionCode = 'UNK'
AND CompensationGradeProfile IN ('Japan JPN', 'Taiwan TWN', 'China CNA',
'Australia AUS', 'Singapore SGP');
UPDATE HRBI
SET payGroupRegionCode = 'EMEA'
WHERE PayGroupRegionCode = 'UNK'
AND CompensationGradeProfile IN ('Luxembourg LUX','Romania ROU');
请注意,由于您没有使用多个表,因此可以在查询(查询)的字段列表中省略表名。
替代方案(未经测试)
自从我上次使用Access以来已经有一段时间了,但也许你可以试试这个:
UPDATE HRBI
SET payGroupRegionCode = IIF(
CompensationGradeProfile IN ('Japan JPN', 'Taiwan TWN', 'China CNA',
'Australia AUS', 'Singapore SGP'),
'APJ',
IIF(
CompensationGradeProfile IN ('Luxembourg LUX','Romania ROU'),
'EMEA',
PayGroupRegionCode
)
)
WHERE PayGroupRegionCode = 'UNK';