1)如果只有优/良两种情况,或者除了优(或良),剩余的都设为良(或优):
UPDATE [表一] SET [字段2] = IIF(([字段1] = '甲'),'优','良');
2)如果除了优良以外还有多种情况,不能都是优或者良:
Private Sub test()
Dim strSQL As String
strSQL = "UPDATE [表一] SET [字段2] ='" & myFunction([字段1]) & "'"
DoCmd.Runsql strSQL
End Sub
Private Function myFunction(x As string)
Select Case x
Case '甲'
myFunction = '优'
Case '乙'
myFunction = '良'
Case else
myFunction = ''
End Select
End Function作者: ^_^ 时间: 2003-12-26 02:29
谢谢阿罗大侠,这个问题困扰我好长时间了,没想到来这里这么快就的到了指导!再次感谢!作者: ^_^ 时间: 2003-12-26 02:56
请教阿罗大侠,如果学习您上面教给我的语句,看什么书可以学到?
因为是要做很多字段组合成的某些条件再更新某个字段。
即:‘
字段1是"甲" AND 字段2是"男" 则更新字段3为"Y1"
字段1是"乙" AND 字段2是"男" 则更新字段3为"Y2"
字段1是"甲" AND 字段2是"女" 则更新字段3为"X1"
字段1是"乙" AND 字段2是"女" 则更新字段3为"X2"
Private Function f_test(a As String, b As String) '///a,b代表字段1和2
If a="甲" then
f_test=IIF(b="男", "Y1", "X1")
else
f_test=IIF(b="男", "Y2", "X2")
end if
End Function