我有一个字段[等级]有几个可能的值:1,1.5,2,2.5,3,...,5.5,6
我需要在查询中添加一个新字段,名为" Gradesally"符合以下标准:
if Grade <2 F else
if Grade <3 E else
if Grade <4 D else
if Grade <5 C else
if Grade <6 B else
if Grade ==6 A
我想我知道如何写标准:
= IIf([Grade]>2,"F",IIf([Grade]<3,"E",IIf([Grade]<4,"D",IIf([Grade]<5,"C",IIf([Grade]<6,"B","A"))))))
但我的字段名称有问题。我试过了
Grades verbally: "" - works but returns nothing
Grades verbally: [Grade] - data type mismatch
Grades verbally: Null - works but returns nothing
我该怎么办?
答案 0 :(得分:2)
您可以使用以下公式:
=Chr(71-Int([Grade]))
答案 1 :(得分:1)
你的条件不太正确。这样做你想要的吗?
SELECT IIf([Grade] < 2, "F",
IIf([Grade] < 3, "E",
IIf([Grade] < 4, "D",
IIf([Grade] < 5, "C",
IIf([Grade] < 6, "B" , "A")
)
)
)
) as [Grade Verbally]
你应该使用SWITCH()
:
SELECT SWITCH([Grade] < 2, "F",
[Grade] < 3, "E",
[Grade] < 4, "D",
[Grade] < 5, "C",
[Grade] < 6, "B",
[Grade] >= 6, "A"
) as [Grade Verbally]