简体   繁体   English

SQL INSERT INTO SELECT 和 INNER JOIN

[英]SQL INSERT INTO with SELECT and INNER JOIN

I hope you can help me with this little problem.我希望你能帮我解决这个小问题。 I am not quite sure of how to explain the situation to you, so I will just give it a try.我不太确定如何向您解释这种情况,所以我将尝试一下。

What I am trying to do is the following:我想做的是以下几点:

I want to insert some specific values and parameters (which I type in myself) into the table RFC_Risks, so basically every time I find a specific reason inside the table RCF_Risks, I want to write a new row that updates the priority of the RfC, every time that happens, the position shall be increased by 1.我想将一些特定的值和参数(我自己输入)插入到表 RFC_Risks 中,所以基本上每次我在表 RCF_Risks 中找到特定原因时,我都想写一个新行来更新 RfC 的优先级,每次发生这种情况时,position 应增加 1。

My problem is now, that when I run this statement, I just get the SELECT part:-), not inserting is done, neither do I get a SQL statement error or anything like that.我现在的问题是,当我运行这个语句时,我只得到 SELECT 部分:-),没有插入完成,我也没有得到 SQL 语句错误或类似的东西。 I just type in the parameters and then I get a SELECT Table thats all.我只需输入参数,然后我得到一个SELECT表就是这样。

I'm using MS Access 2010 and I hope you can help me out with my "little" problem.我正在使用 MS Access 2010,希望您能帮助我解决我的“小”问题。

INSERT INTO RFC_Risks (RFC_No, RiskPos, Datum, Comments, RiskPrio, Reason)
SELECT RFC_Risks.RFC_No, (RFC_Risks.RiskPos +1) AS RiskPos, [Aktuelles Datum] AS Datum, [Kommentartext] AS Comments, [Neue Prio] AS RiskPrio, RFC_Risks.Reason 
FROM RFC_Risks INNER JOIN Risk_Reasons ON RFC_Risks.Reason = Risk_Reasons.Reasontext 
WHERE RFC_Risks.Reason = Risk_Reasons.Reasontext;

I can't spot anything about your SQL statement which would prevent it from executing and/or throw an error.我无法发现有关您的 SQL 语句的任何内容,这会阻止它执行和/或引发错误。 (I think your WHERE clause is redundant, but that should not cause the db engine to reject it.) What method are you using to "run" it? (我认为您的 WHERE 子句是多余的,但这不应该导致数据库引擎拒绝它。)您使用什么方法来“运行”它?

If you're using the Access query designer, and switch from Design View to Datasheet View, your query isn't actually executed... Datasheet View will show you the rows which would be affected if the query were executed.如果您正在使用 Access 查询设计器,并从设计视图切换到数据表视图,您的查询实际上并没有被执行...数据表视图将向您显示在执行查询时会受到影响的行。

The situation is the same as if you were building a delete query in the query designer... Datasheet View would show you which rows would be deleted if the query were executed, but switching to Datasheet View does not delete those rows.情况与您在查询设计器中构建删除查询相同...数据表视图将显示如果执行查询将删除哪些行,但切换到数据表视图不会删除这些行。

To execute the query, click the icon which has a red exclamation point.执行查询,请单击带有红色感叹号的图标。

Try enclosing the subselect in parentheses.尝试将子选择括在括号中。

You need to execute your query.您需要执行查询。 If you only display it in Datasheet View, the SELECT Statement is executed and displayed to you as a kind of preview.如果您只在数据表视图中显示它,则执行 SELECT 语句并作为一种预览显示给您。

To really execute the query, when you are in design mode, you can click on the "Run" button (a red exclamation mark) in the toolbar.要真正执行查询,当您处于设计模式时,您可以单击工具栏中的“运行”按钮(红色感叹号)。 You can also double-click on the query in the database window.也可以双击数据库window中的查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM