[英]I am trying to import data from an access database using SQL SELECT method in VBA
I am trying to import data from an access database using SQL SELECT method in VBA. I have already imported the data from one table using SQL, this specific line worked for me.我正在尝试在 VBA 中使用 SQL SELECT 方法从访问数据库导入数据。我已经使用 SQL 从一个表中导入了数据,这一行对我有用。
SQL = "Select * FROM grades"
. SQL = "Select * FROM grades"
。 The database has three tables grades, courses, and student.该数据库具有三个表 grades、courses 和 student。 I am trying to import just the FirstName and LastName data from the student table and just the CourseName from the course table as all the rest of the data is already in the grades table.
我正在尝试仅从学生表中导入 FirstName 和 LastName 数据,并仅从课程表中导入 CourseName,因为所有数据 rest 都已在成绩表中。 The grades and courses table both have coursecode which connects the Coursename in the courses table.
成绩表和课程表都有课程代码,它连接课程表中的课程名称。 Both the student and grade table have studentID which is connected to the first and last name in the student table.
学生表和年级表都有学生 ID,它与学生表中的名字和姓氏相关联。 I am not sure how to write the SQl code in VBA order to get the coursename from the course table match the coursecode from the grades table and the student id from the grades table match the first and last name from the student table.
我不确定如何在 VBA 中编写 SQl 代码,以使课程表中的课程名称与成绩表中的课程代码相匹配,成绩表中的学生 ID 与学生表中的名字和姓氏相匹配。 Any help or leads?
任何帮助或线索?
' SQL = "SELECT *, courses.CourseName" & "FROM grades INNER JOIN courses" & "WHERE grades.CourseCode = grades.course"
this is my logic from what I found in the documentation but it doesnt seem to be working.这是我在文档中发现的逻辑,但它似乎不起作用。
You should need something similar to this.你应该需要类似的东西。
select g.*, c.CourseName, s.FirstName, s.LastName
from Grades g
inner join Students s
on s.StudentID = g.StudentID
inner join Courses c
on c.CourseCode = g.CourseCode
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.