使用 SET / WHERE 语句更新数据
Update data using SET / WHERE statements
有没有办法使用 WHERE 语句更新这些记录?
UPDATE HRBIQuery SET HRBIQuery.PaySegmentMultiplier = '1.35',
HRBIQuery.PaySegmentMultiplier = '1.25', HRBIQuery.PaySegmentMultiplier = '1.15',
HRBIQuery.PaySegmentMultiplier = '.90', HRBIQuery.PaySegmentMultiplier = '.60',
HRBIQuery.PaySegmentMultiplier = '.40'
WHERE (HRBIQuery.BasePayRangeSegment = 'Below segment 1' AND HRBIQuery.PayGroupCountryDesc = 'France',
HRBIQuery.BasePayRangeSegment = 'S1' AND HRBIQuery.PayGroupCountryDesc = 'France',
HRBIQuery.BasePayRangeSegment = 'S2' AND HRBIQuery.PayGroupCountryDesc = 'France',
HRBIQuery.BasePayRangeSegment = 'S3' AND HRBIQuery.PayGroupCountryDesc = 'France',
HRBIQuery.BasePayRangeSegment = 'S4' AND HRBIQuery.PayGroupCountryDesc = 'France',
HRBIQuery.BasePayRangeSegment = 'S5' AND HRBIQuery.PayGroupCountryDesc = 'France');
谢谢!
这里有几个选项。
选项 1:在查询中使用 switch 语句。
UPDATE HRBIQuery SET HRBIQuery.PaySegmentMultiplier =
switch(HRBIQuery.BasePayRangeSegment = 'Below segment 1',1.35,
HRBIQuery.BasePayRangeSegment = 'Below segment 1',1.35,
HRBIQuery.BasePayRangeSegment = 'S1',1.25,
HRBIQuery.BasePayRangeSegment = 'S2',1.15,
HRBIQuery.BasePayRangeSegment = 'S3',.90,
HRBIQuery.BasePayRangeSegment = 'S4',.60,
HRBIQuery.BasePayRangeSegment = 'S5',.40)
WHERE HRBIQuery.BasePayRangeSegment IN('Below segment 1','S1','S2','S3','S4','S5')
AND HRBIQuery.PayGroupCountryDesc = 'France'
选项 2:使用嵌套 IIF 语句的一个查询。
UPDATE HRBIQuery SET HRBIQuery.PaySegmentMultiplier =
IIF(HRBIQuery.PaySegmentMultiplier='Below segment 1',1.35,
IIF(HRBIQuery.PaySegmentMultiplier='S1',1.25,
IIF(HRBIQuery.PaySegmentMultiplier='S2',1.15,
IIF(HRBIQuery.PaySegmentMultiplier='S3,.90,
IIF(HRBIQuery.PaySegmentMultiplier='S4',.60,
IIF(HRBIQuery.PaySegmentMultiplier='S1',.40))))))
WHERE HRBIQuery.BasePayRangeSegment IN('Below segment 1','S1','S2','S3','S4','S5')
AND HRBIQuery.PayGroupCountryDesc = 'France'
选项 3:使用 6 个不同的查询。我不会把所有六个都打出来。希望你明白了。
UPDATE HRBIQuery SET HRBIQuery.PaySegmentMultiplier = 1.35
WHERE HRBIQuery.BasePayRangeSegment = 'Below segment 1'
AND HRBIQuery.PayGroupCountryDesc = 'France'
选项 4:使用自定义函数。创建一个 public 函数并在您的查询中调用它。
UPDATE HRBIQuery SET HRBIQuery.PaySegmentMultiplier = custom_function(HRBIQuery.BasePayRangeSegment)
WHERE HRBIQuery.BasePayRangeSegment IN('Below segment 1','S1','S2','S3','S4','S5')
AND HRBIQuery.PayGroupCountryDesc = 'France'
自定义函数应该是这样的(抱歉有任何语法错误,但你应该明白了):
public function custom_function(value)
dim return_value as double
select case value
case 'Below segment 1'
return_value = 1.35
case 's1'
return_value = 1.25
case 'S2'
return_value = 1.15
case 'S3'
return_value = .90
case 'S4'
return_value = .60
case 'S5'
return_value = .40
End select
return return_value
end function
有没有办法使用 WHERE 语句更新这些记录?
UPDATE HRBIQuery SET HRBIQuery.PaySegmentMultiplier = '1.35',
HRBIQuery.PaySegmentMultiplier = '1.25', HRBIQuery.PaySegmentMultiplier = '1.15',
HRBIQuery.PaySegmentMultiplier = '.90', HRBIQuery.PaySegmentMultiplier = '.60',
HRBIQuery.PaySegmentMultiplier = '.40'
WHERE (HRBIQuery.BasePayRangeSegment = 'Below segment 1' AND HRBIQuery.PayGroupCountryDesc = 'France',
HRBIQuery.BasePayRangeSegment = 'S1' AND HRBIQuery.PayGroupCountryDesc = 'France',
HRBIQuery.BasePayRangeSegment = 'S2' AND HRBIQuery.PayGroupCountryDesc = 'France',
HRBIQuery.BasePayRangeSegment = 'S3' AND HRBIQuery.PayGroupCountryDesc = 'France',
HRBIQuery.BasePayRangeSegment = 'S4' AND HRBIQuery.PayGroupCountryDesc = 'France',
HRBIQuery.BasePayRangeSegment = 'S5' AND HRBIQuery.PayGroupCountryDesc = 'France');
谢谢!
这里有几个选项。
选项 1:在查询中使用 switch 语句。
UPDATE HRBIQuery SET HRBIQuery.PaySegmentMultiplier =
switch(HRBIQuery.BasePayRangeSegment = 'Below segment 1',1.35,
HRBIQuery.BasePayRangeSegment = 'Below segment 1',1.35,
HRBIQuery.BasePayRangeSegment = 'S1',1.25,
HRBIQuery.BasePayRangeSegment = 'S2',1.15,
HRBIQuery.BasePayRangeSegment = 'S3',.90,
HRBIQuery.BasePayRangeSegment = 'S4',.60,
HRBIQuery.BasePayRangeSegment = 'S5',.40)
WHERE HRBIQuery.BasePayRangeSegment IN('Below segment 1','S1','S2','S3','S4','S5')
AND HRBIQuery.PayGroupCountryDesc = 'France'
选项 2:使用嵌套 IIF 语句的一个查询。
UPDATE HRBIQuery SET HRBIQuery.PaySegmentMultiplier =
IIF(HRBIQuery.PaySegmentMultiplier='Below segment 1',1.35,
IIF(HRBIQuery.PaySegmentMultiplier='S1',1.25,
IIF(HRBIQuery.PaySegmentMultiplier='S2',1.15,
IIF(HRBIQuery.PaySegmentMultiplier='S3,.90,
IIF(HRBIQuery.PaySegmentMultiplier='S4',.60,
IIF(HRBIQuery.PaySegmentMultiplier='S1',.40))))))
WHERE HRBIQuery.BasePayRangeSegment IN('Below segment 1','S1','S2','S3','S4','S5')
AND HRBIQuery.PayGroupCountryDesc = 'France'
选项 3:使用 6 个不同的查询。我不会把所有六个都打出来。希望你明白了。
UPDATE HRBIQuery SET HRBIQuery.PaySegmentMultiplier = 1.35
WHERE HRBIQuery.BasePayRangeSegment = 'Below segment 1'
AND HRBIQuery.PayGroupCountryDesc = 'France'
选项 4:使用自定义函数。创建一个 public 函数并在您的查询中调用它。
UPDATE HRBIQuery SET HRBIQuery.PaySegmentMultiplier = custom_function(HRBIQuery.BasePayRangeSegment)
WHERE HRBIQuery.BasePayRangeSegment IN('Below segment 1','S1','S2','S3','S4','S5')
AND HRBIQuery.PayGroupCountryDesc = 'France'
自定义函数应该是这样的(抱歉有任何语法错误,但你应该明白了):
public function custom_function(value)
dim return_value as double
select case value
case 'Below segment 1'
return_value = 1.35
case 's1'
return_value = 1.25
case 'S2'
return_value = 1.15
case 'S3'
return_value = .90
case 'S4'
return_value = .60
case 'S5'
return_value = .40
End select
return return_value
end function