我有一张有等级的桌子。现在,我希望等级在Microsoft Access中具有后缀“ St”,“ nd”,“ rd”,“ th”。我想知道是否有一种方法可以使用访问查询来实现。感谢您的提前答复
答案 0 :(得分:1)
此Chip Pearsons网站上的代码可以解决问题:
Public Function OrdinalSuffix(ByVal Num As Long) As String
Dim N As Long
Const cSfx = "stndrdthththththth" ' 2 char suffixes
N = Num Mod 100
If ((Abs(N) >= 10) And (Abs(N) <= 19)) _
Or ((Abs(N) Mod 10) = 0) Then
OrdinalSuffix = "th"
Else
OrdinalSuffix = Mid(cSfx, _
((Abs(N) Mod 10) * 2) - 1, 2)
End If
End Function
您可以通过以下方式将其写入查询中:
SELECT MyField & OrdinalSuffix(MyField)
FROM MyTable
仅公式的版本为:
IIf(MyField-100*INT(MyField/100)>=10 And MyField-100*INT(MyField/100)<=14,"th",Choose(MyField-10*INT(MyField/10)+1,"th","st","nd","rd","th","th","th","th","th","th"))
写为
SELECT MyField & IIf(MyField-100*INT(MyField/100)>=10 And MyField-100*INT(MyField/100)<=14,"th",Choose(MyField-10*INT(MyField/10)+1,"th","st","nd","rd","th","th","th","th","th","th"))
FROM MyTable