两个表之间的dlookup(嵌套的dlookup无效)

时间:2016-09-22 17:25:56

标签: sql ms-access

我已经嵌套了两个dlookup函数,它似乎没有工作。请协助? 问题: 表一包含学生成绩:

----------
Student_ID     Name      Grade
2892838392     Name1      A+
2892838398     Name3      D+
2892838397     Name2      B+
----------

表二包含字母等级之间的价值转换

Grade          Value
A+             100
A              95
A-             90

我在一个查询中编写了两个dLookkup公式来提取信息。

Expr1: DLookUp("[Value]","[Grade_Scale]","[Grade]='TESTGRADE'")
Expr2: DLookUp("[Freshman - English]","[NJAE Applicant - NJAE GPA Calculator]","[ID]= " & [ID])

但出于某种原因,当我将两者嵌套在一起时,我在视图中得到一个#Error。

Student_Points: DLookUp("[Value]","[Grade_Scale]","[Grade]=" & DLookUp("[Freshman - English]","[NJAE Applicant - NJAE GPA Calculator]","[ID]= " & [ID]))

请协助

4 个答案:

答案 0 :(得分:3)

您是否只想将价值附加到成绩?为什么不使用加入?这个可行:

SELECT t1.student_id, t1.name, t1.grade, t2.value
FROM t1
INNER JOIN t2
ON t1.grade = t2.grade

答案 1 :(得分:2)

您的语法不正确。我认为kbball提交的连接更容易,并在评论中提到,但是为了将来使用,这里是更正的语法:

Student_Points: DLookUp("[Value]","[Grade_Scale]","[Grade]= '" & DLookUp("[Freshman - English]","[NJAE Applicant - NJAE GPA Calculator]","[ID]= '" & [ID] & "'") & "'")

criteria参数需要围绕被测试值的单引号,包括嵌套Dlookup的结果。

答案 2 :(得分:1)

您可以在DLookup中使用 SQL

Student_Points: DLookUp("[Value]","[Grade_Scale]","[Grade] = (Select [Freshman - English] From [NJAE Applicant - NJAE GPA Calculator] Where [ID] = " & [ID] & ")")

答案 3 :(得分:0)

根据有效的DLookup,[Grade]是一个文本字段,所以你需要这个:

Student_Points: DLookUp("[Value]","[Grade_Scale]","[Grade]='" & DLookUp("[Freshman - English]","[NJAE Applicant - NJAE GPA Calculator]","[ID]=" & [ID]) & "'")

(用单引号括起整个第二个替换TESTGRADE的DLookup)