简体   繁体   English

我正在尝试使用 VBA 中的 SQL SELECT 方法从访问数据库导入数据

[英]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.

相关问题 我正在尝试从数据库中提取数据并将其存储到 xml 文件中。 我正在使用 Sql 查询“Select * from”来提取数据 - I am trying to pull data from a database and store it into a xml file. I am using a Sql query "Select * from "for pulling data Access数据库:如何从SQL数据库/表中导入查询到的数据 - Access Database: How to import the queried data from SQL database/table 使用 Excel VBA 将表从 SQL 导入到 Access - Import table from SQL to Access using Excel VBA 我正在尝试使用 python sql 访问存储在雪花表中的数据。 下面是我要访问的下面给出的列 - I am trying to access the data stored in a snowflake table using python sql. Below is the columns given below i want to access 我正在尝试使用SQL从数据库动态获取下拉菜单项 - I am trying to get the drop down menu items dynamiclly from the database using SQL 我有一个本地SQL Server数据库。 它在本地工作。 我正在尝试从本地数据库传递到Azure。使用.net无法正常工作 - I have a local SQL Server Data base. It's working in local. I am trying to pass from Local database to Azure.It's not working using .net 我正在尝试从2个mysql表中选择数据到1个查询中 - I am trying to select data from 2 mysql tables into 1 query 我正在尝试使用提供的json文件中的数据创建数据库 - I am trying to create a database using the data in the json file provided 我正在尝试使用sql将数据添加到现有行中的列 - I am trying to add data to a column in an existing row using sql 如何使用VBA将Access表单中的数据插入到sql表中? - How can I insert data from an Access form into a sql table using VBA?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM