SQL INSERT INTO 使用 SELECT 和 INNER JOIN

发布于 2024-11-29 06:57:08 字数 720 浏览 5 评论 0原文

我希望你能帮我解决这个小问题。我不太确定如何向你解释这种情况,所以我会尝试一下。

我想做的是:

我想将一些特定的值和参数(我自己输入的)插入到表 RFC_Risks 中,所以基本上每次我在表 RCF_Risks 中找到特定原因时,我想写一个更新 RfC 优先级的新行,每次发生这种情况,位置都应增加 1。

我现在的问题是,当我运行此语句时,我只得到 SELECT 部分:-),而不是插入完成,两者都不我是否收到 SQL 语句错误或类似的错误?我只需输入参数,然后就得到一个 SELECT 表,仅此而已。

我正在使用 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 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.

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. I just type in the parameters and then I get a SELECT Table thats all.

I'm using MS Access 2010 and I hope you can help me out with my "little" problem.

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

枕头说它不想醒 2024-12-06 06:57:08

我无法发现有关您的 SQL 语句的任何内容会阻止它执行和/或引发错误。 (我认为您的 WHERE 子句是多余的,但这不应导致数据库引擎拒绝它。)您使用什么方法来“运行”它?

如果您使用 Access 查询设计器,并从设计视图切换到数据表视图,则您的查询实际上并未执行...数据表视图将向您显示执行查询时将受到影响的行。

这种情况与您在查询设计器中构建删除查询相同...数据表视图将显示如果执行查询将删除哪些行,但切换到数据表视图不会显示删除这些行。

执行查询,请单击带有红色感叹号的图标。

I can't spot anything about your SQL statement which would prevent it from executing and/or throw an error. (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?

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.

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.

网名女生简单气质 2024-12-06 06:57:08

尝试将子选择括在括号中。

Try enclosing the subselect in parentheses.

じ违心 2024-12-06 06:57:08

您需要执行您的查询。如果您仅在数据表视图中显示它,则会执行 SELECT 语句并以预览形式向您显示。

要真正执行查询,当您处于设计模式时,可以单击工具栏中的“运行”按钮(红色感叹号)。您还可以双击数据库窗口中的查询。

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文