VBA中的SQL QUERY(SQL QUERY in VBA)

编程入门 行业动态 更新时间:2024-10-26 04:25:28
VBA中的SQL QUERY(SQL QUERY in VBA)

这有什么问题? 我想列出那些where material number from mm = Child_Material_Number From bom and Parent_Material_Number = ' ' 。

这是我的代码:

rs.open("SELECT Material_Number,Material_Descr_HU FROM mm m" & _ " WHERE " & _ "Child_Material_Number FROM bom" & _ " = Material_Number FROM mm) " & _ "AND Parent_Material_Number = ''", cn, _ ADODB.CursorTypeEnum.adOpenKeyset, _ ADODB.LockTypeEnum.adLockOptimistic _ )

What's the problem with this? I want to list those items where material number from mm = Child_Material_Number From bom and Parent_Material_Number = ' '.

Here is my code:

rs.open("SELECT Material_Number,Material_Descr_HU FROM mm m" & _ " WHERE " & _ "Child_Material_Number FROM bom" & _ " = Material_Number FROM mm) " & _ "AND Parent_Material_Number = ''", cn, _ ADODB.CursorTypeEnum.adOpenKeyset, _ ADODB.LockTypeEnum.adLockOptimistic _ )

最满意答案

在SQL中,子句FROM告诉服务器在搜索数据时要查看哪些表或查询。 您正在寻找的查询是这样的:

SELECT mm.Material_Number, mm.Material_Descr_HU FROM mm INNER JOIN bom ON mm.Material_Number = bom.Child_Material_Number WHERE bom.Parent_Material_Number = ''

另外,始终牢记基本的SQL语句结构,即:

SELECT [fields] FROM [tables or queries] WHERE [condition] ORDER BY [fields]

查询中的问题是您在WHERE子句之后和之内包含FROM子句。 当然,如果你要嵌套查询,你可以这样做 - 以及更多 - 但是你需要第二个SELECT子句。

有很多SQL教程,如果您计划将来使用数据,它们值得一看。

In SQL, the clause FROM tells the server what tables or queries to look into in search of the data. The query you are looking for is something like this:

SELECT mm.Material_Number, mm.Material_Descr_HU FROM mm INNER JOIN bom ON mm.Material_Number = bom.Child_Material_Number WHERE bom.Parent_Material_Number = ''

Also, always have in mind the basic SQL statement structure, which is:

SELECT [fields] FROM [tables or queries] WHERE [condition] ORDER BY [fields]

The problem in your query is that you are including the FROM clause after and within the WHERE clause. Of course, you could do this -and more- if you are nesting queries, but then you'd need a second SELECT clause.

There are plenty of SQL tutorials out there, and they are worth a look if you are planning to work with data in the future.

更多推荐

本文发布于:2023-07-19 20:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1186759.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:VBA   SQL   QUERY

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!