使用SET / WHERE语句更新数据

时间:2015-09-08 21:38:35

标签: ms-access jet-sql

有没有办法使用WHERE语句更新这些记录?

PFQuery *query = [PFQuery queryWithClassName:@"News"];
// Any additional steps to limit the received data.
NSArray *data = [query findObjects];

谢谢!

1 个答案:

答案 0 :(得分:2)

你在这里有几个选择 选项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:使用自定义功能。创建一个公共函数并在查询中调用它。

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